Matthew Steven Monkan
Matthew Steven Monkan

Reputation: 9160

Comparison of two Solr queries

Assume that by themselves the following:

Default operator is OR.

If users will be making many queries like what I list below:

Namely,

or

which would I want to use? I know that the individual fq's will be cached, but I'm wondering if there a difference of what Solr will do in memory or something I may not be aware of when Solr does large computations like this. In the end, the results are the same, but what are the pros and cons of each?

Upvotes: 0

Views: 442

Answers (2)

Bob Yoplait
Bob Yoplait

Reputation: 2501

Query A: you have a first result set for "foo" that is getting filtered

Query B: you have three result sets for which you compute an intersection.

So if "type:SalesOrder" gives a huge result set for example, queryA will be much more efficient.

If the query is not plain text with analyzers, but it is an ID for example (shop:1234), the most efficient will be to use as a query the one that gives the smallest result set (q=refId:12345 maybe ?) and use the two other parameters as filters

Upvotes: 0

Jayendra
Jayendra

Reputation: 52809

Query A: q=foo&fq=type:SalesOrder&fq=refId:12345

If you want to limit the number of results as in a filter and not search over the fields you should use filter queries.

fq - Provide an optional filtering query. Results of the query are restricted to searching only those results returned by the filter query. Filtered queries are cached by Solr. They are very useful for improving the speed of complex queries.

If your case as it seems you want to filter out the results which have the type as SalesOrder and refid 12345, filter query seems right instead of using them in the query q param.

Upvotes: 2

Related Questions