Solr filter-query vs main-query
Asked Answered
O

2

60

Solr docs state that filter queries, unlike the main query, do not influence the document score. What does this mean exactly, preferably with an example.

Occupation answered 4/1, 2012 at 17:9 Comment(0)
F
65

A FilterQuery ONLY stores document IDS. This makes it very fast to apply the filter to include/exclude documents. Good examples of this are when filtering products from search based on Country, Product Type, Availability, etc.

A normal query can perform the exact same function, but it has a very complex scoring system to determine "relevance". I believe the documentation is indicating that scoring is only done on the Main Query, not on the Filter Query. This should also increase query speed.

So, I can query for:

description:Kohler AND productType:Toilet

Or I can query for:

description:Kohler
with a FQ of productType:Toilet

The results would be the same, but the scores would be different. Also, if you get many different queries throughout the day that are for productType:Toilet, the FilterQuery would be cached making the overall query time faster.

Fulmis answered 4/1, 2012 at 17:20 Comment(4)
So if for example at indexing there is term boosting on "productType", the results can be sorted differently if productType is set in a FilterQuery instead of the main Query, such that if it is in the Query, those documents with a higher productType score will be at the top, while if it is in a FilterQuery those docs with a higher productType score might be at the bottom because score is not applied since it is in a FilterQuery. Am I understanding you right?Occupation
Correct. However, if you put productType in the main Query as an AND clause, you wouldn't get back any other productTypes anyway. So this may be of limited value. But, you what you said means you understand how it works.Fulmis
Yes you have a point, because I was incorrectly assuming an FTS on productType as well (therefore more than one productType could potentially be returned, but usually there is no FTS on *Type). Thanks.Occupation
I suppose this scoring will be relevant when you have a composite query with OR'ed sub-queries for fields with different scores.Betoken
A
7

fq is intended for a fixed list of values. If you search on q=sunroof+stereo and fq=Mustang solr will do text analysis on the q parameter since q=sunroof+stereo and q=stereo+sunroof will return the same result set. But when filtering the search via fq there is no analysis applied to the fq param and it's assumed all returned documents will match the fq so there is no need for it to modify the score of the docs that match.

Absorptivity answered 4/1, 2012 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.