Web / Apache Solr Interview questions
What is the difference between q and fq parameters in Solr?
Both q and fq restrict which documents are considered, but they behave very differently underneath.
- q is the main relevance query. It affects the score of each document, which drives ranking order.
- fq (filter query) narrows the result set further but contributes no score. Documents either match or they don't.
The practical reason to prefer fq for things like category:electronics or inStock:true is caching: each distinct fq clause is cached independently in the filter cache as a bitset, and that bitset can be reused across many different q values. Putting the same clause in q instead recomputes scoring every time and pollutes the query result cache with one entry per unique combined query.
More Related questions...