解决方法
我推荐这个问题
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 }