对于此问题,我建议使用ClientUtils.toQueryString。
@Test
public void solrQueryToURL() {
SolrQuery tmpQuery = new SolrQuery("some query");
Assert.assertEquals("?q=some+query", ClientUtils.toQueryString(tmpQuery, false));
}
在源代码HttpSolrServer你可以看到,这是使用的Solrj代码本身这个原因。
public NamedList<Object> request(final SolrRequest request, final ResponseParser processor) throws SolrServerException, IOException {
// ... other code left out
if( SolrRequest.METHOD.GET == request.getmethod() ) {
if( streams != null ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "GET can't send streams!" );
}
method = new HttpGet( baseUrl + path + ClientUtils.toQueryString( params, false ) );
// ... other code left out
}