Is there a SolrJ query builder?

◇◆丶佛笑我妖孽 提交于 2020-04-10 02:53:41

问题


Using solr 5.2.0 was wondering is there a query builder API/Jar/Ckient similar to Elasticsearch query builder API or do we have to bassically do String Kungfu to build queries in Solr?


回答1:


Unfortunately, in SolrJ there is no such thing as a Builder for the query that goes into the q-Parameter.

BUT: As Solr already operates on Lucene, we can as well use the Lucene QueryBuilder. The resulting Query objects (e.g. PhraseQuery) have a toString() method that provides you with the query string you would otherwise have to assemble by hand.




回答2:


You might want to use SolrQuery

  SolrQuery solrQuery=new SolrQuery();
  solrQuery.set("q",query);
  solrQuery.set("rows",5000);
  QueryResponse response=solrServers.query(solrQuery);

For more examples please refer this link




回答3:


SolrQuery is the class that hidden the complexity of string concatenation and it has plenty of methods that helps to build the query. This example show as use it with a fluent interface.

CloudSolrClient client = new CloudSolrClient.Builder()
                                            .withZkHost("zookeeper-host:2181")
                                            .build();
QueryResponse resp = client.query(new SolrQuery()
                                  .setRows(10)
                                  .setQuery(query)
                                  .setFields("title", "manufacturer", "price"));


来源:https://stackoverflow.com/questions/42392380/is-there-a-solrj-query-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!