Java – how to convert solrquery (solrj) to URL?
•
Java
When using solrj, I want to know how to use Solr query syntax to convert solrquery objects to their URL representation I tried to use it Tostring() method, but it does not return the correct query representation What else can I do?
Solution
I recommend clientutils toQueryString.
@Test public void solrQueryToURL() { SolrQuery tmpQuery = new SolrQuery("some query"); Assert.assertEquals("?q=some+query",ClientUtils.toQueryString(tmpQuery,false)); }
In the source code httpsolrserver, you can see that solrj code itself uses it for this reason
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 }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码