问题
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