本文介绍了如何将SolrQuery(SOLRJ)转换为URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用SOLRJ时,我想知道如何使用SOLR查询语法将SolrQuery对象转换为其URL表示形式。我尝试使用.toString()方法,但它没有返回正确的查询表示。还有其他一些方法吗?
While using SOLRJ I would like to know how can I convert SolrQuery object to its URL representation with SOLR query syntax. I tried to use .toString() method but it doesnt return proper query representation. Is there some other way how to do it?
推荐答案
我推荐就此而言。
@Test
public void solrQueryToURL() {
SolrQuery tmpQuery = new SolrQuery("some query");
Assert.assertEquals("?q=some+query", ClientUtils.toQueryString(tmpQuery, false));
}
在您可以看到Solrj代码本身使用了这个原因。
Within the source code of HttpSolrServer you can see that this is used by the Solrj code itself 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
}
这篇关于如何将SolrQuery(SOLRJ)转换为URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!