Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr query (q) or filter query (fq)

Tags:

solr

I have a ~1 mil product document Solr index. I also have a whole bunch of UI filters such as, categories, tabs, price ranges, sizes, colors, and some other filters.

Is it the right way to have the q selecting everything (q=\*:\*) while all other filters in the fq? example:

fq=(catid:90 OR catid:81) AND priceEng:[38 TO 40] AND (size:39 OR size:40 OR size:41 OR size:50 OR size:72) AND (colorGroup:Yellow OR colorGroup:Violet OR colorGroup:Orange ... AND (companyId:81 OR companyId:691 OR companyId:671 OR companyId:628 OR companyId:185 OR companyId:602 OR ... AND endShipDays:[* TO 7])

To me, everything from categories to companyIds, from colors and sizes, etc are just filters. Any problem in performance in the future growth with this approach ? Should I put some of the queries in the q, which ones ?

Thank you,

like image 504
Tommy Lord Avatar asked Jul 24 '12 08:07

Tommy Lord


People also ask

What is FQ in Solr query?

The fq (Filter Query) Parameter The fq parameter defines a query that can be used to restrict the superset of documents that can be returned, without influencing score. It can be very useful for speeding up complex queries, since the queries specified with fq are cached independently of the main query.

How do you write FQ in Solr?

In the lucid works SOLR training they suggested you do multiple fq parameters instead of a single one joined with AND for performance reasons. So in the sample it would be q=*:*&fq=(catid:90 OR catid:81)&fq=priceEng:[38 TO 40]&fq=.... etc.

How do you directly query Solr?

Trying a basic query The main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser). If this is new to you, please check out the Solr Tutorial. Adding debug=query to your request will allow you to see how Solr is parsing your query.


1 Answers

It's preferable to use Filter Query over normal Query wherever possible.

FilterQuery is able to take advantage of the FilterCache, which would be a huge performance boost in comparison to your queries.

like image 194
Jayendra Avatar answered Sep 28 '22 11:09

Jayendra