Lucene query vs filter?
They both does similar things like termquery filters by term value, filter i guess is there for similar purpose.
When would you use filter and when query?
Just starting on lucene today so trying to clear concept
Lucene is a query language that can be used to filter messages in your PhishER inbox. A query written in Lucene can be broken down into three parts: Field The ID or name of a specific container of information in a database. If a field is referenced in a query string, a colon ( : ) must follow the field name.
Frequently used filters will be cached automatically by Elasticsearch, to speed up performance. Filter context is in effect whenever a query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.
Filters are systems or elements used to remove substances such as dust or dirt, or electronic signals, etc., as they pass through filtering media or devices. Filters are available for filtering air or gases, fluids, as well as electrical and optical phenomena.
Filtering is a useful way to see only the data that you want displayed in Access databases. You can use filters to display specific records in a form, report, query, or datasheet, or to print only certain records from a report, table, or query.
Filter doesn't affect the computation of the score of the non-filtered documents.
For instance imagine the following docs:
1. loc: "uk", "london" text: "i live in london, "london is the best" 2. loc: "london avenue", "london street", "london" text: "I like the shop in london st."
now let's say you do the following query:
q=+loc:"london" +text:"london"
in this query the score of doc 2 is higher than that of doc 1 (because loc
is calculated in the document score)
using a filter:
q=+text:"london" f=+loc:"london"
in this query the score of doc 1 is higher than that of doc 2.
Excuse the Solr style formatting but the overall notion is clear.
Other reasons for using filters are for caching purposes, filters are cached separately from queries so if you have a dynamic query with a static part it would make sense to filter by the static part. In this way the index traversal is limited to the subset of filtered docs.
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