Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene: What is the difference between Query and Filter

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

like image 751
mamu Avatar asked Sep 15 '10 19:09

mamu


People also ask

What is a Lucene query?

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.

What is filter in elastic search?

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.

What are the filter?

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.

What is filter in MS Access?

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.


1 Answers

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.

like image 186
Asaf Avatar answered Oct 05 '22 15:10

Asaf