a blog for those who code

Wednesday 11 January 2017

How to query over multiple fields in Solr

In this post we will be discussing about how to query over multiple fields in Solr. Solr is the popular, blazing-fast, open source enterprise search platform built on Apache Lucene. Solr enables you to easily create search engines which searches websites, databases and files. Since Solr is built Apache Lucene, we have to use Lucene custom query syntax for querying its indexes.

So for normal keyword matching we query Solr by writing name:bill or name:"bill watson". So as per the question we need to query over multiple fields which can be done using the below query

q=firstname:bill AND lastname:watson


If the values are fixed, its better to use Filer queries. Filter queries is used to specify a query that can be used to restrict the sure set of documents that can be returned, without influencing score. The queries specified with fq are cached independently from the main query thus it helps to speed up the complex queries. So if we want to query over multiple fields we can do using the below query :

fq=firstname:bill&fq=lastname:watson


Please Like and Share the CodingDefined Blog, if you find it interesting and helpful.

No comments:

Post a Comment