Search code examples
solrsolrjsolrcloudsolr5solr-query-syntax

Is there a SolrJ query builder?


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?


Solution

  • 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.