I read all answers to the same question and am not any clearer on which one I should use for my usecase and why. Both return the same result. I understand that "FilterQuery would be cached making the overall query time faster", like someone correctly answered.
I also understand that "filtering also allows tagging of facets, so you can tag facets to include all facets that are returned for your query", like someone else also correctly answered.
What I don't understand reading this, is why then anyone would use Q, since FQ seems to be so much better, based on all the answers and books I've seen.
Except, I'm sure there's probably a reason that both exist.
What I would like is to figure out what's best for my use case - the documentation is sorely lacking in useful examples.
Business rule #1: date must always be present in every query.
Business rule #2: 99% of queries are going to use the LATEST date, but RANDOM client and random report.
A Fact: We determined that it’s faceting that is slow, not searching.
QUESTIONS:
Given this search criteria, and these ways to write a query:
A) q=date:20130214 AND client:Joe & facet.field=date & facet.field=client...
B) q=date:20130214 & fq=client:Joe & facet.field=date & facet.field=client...
C) q=client:Joe & fq= date:20130214 & facet.field=date & facet.field=client...
D) q=*:* & fq=date:20130214 & fq=client:Joe & facet.field=date & facet.field=client...
Today, I have D) is used in all cases, but I suspect this is wrong and is causing OOMs in Solr(version 3.6).
Thank you for your help!
The fq filter query parameter in a query to Solr search is used to filter out some documents from the search result without influencing the score of the returned documents. Queries with fq parameters are cached.
Solr Query Syntax. The default Solr query syntax used to search an index uses a superset of the Lucene query syntax. 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).
Solr Query Syntax The default Solr query syntax used to search an index uses a superset of the Lucene query syntax. Trying a basic query The main query for a solr search is specified via the q parameter.
Adding debug=query to your request will allow you to see how Solr is parsing your query. The response section will normally contain the top ranking documents for the query. In this example, no documents matched the query. In the debug section, one can see how the query was parsed, and the fact that text was used as the default field to search.
q
query is the main query of the Request.
It is the one that would allow you to actually search over multiple fields.q
query would decide what score each of the documents has and hence would take part in the relevancy calculation.
q=*:*
will just return all the documents with the same score.
fq
is the filter query used to filter the documents and is not related to search.
So if you have any fixed value which you want to filter on you should use filters to limit your results.fq
does not affect the scoring of the results.
While filtering, Solr uses Filter cache to enhance the performance for the subsequent filter queries.
So ideally, you should check what the requirement demands. If you want to search, you should always use q
, and if you want to filter/limit results you should use fq
.
Facets are just an add-on to the results and do not affect your results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With