Chapter 8. Filters: cross-cutting restrictions
This chapter covers
- Configuring and using dynamic filters
- Caching filters
- Various filter examples
Full-text queries are great for answering a question formulated by a user. However, in some situations, you’ll need to add restrictions that don’t belong to the core of the user question. These are cross-cutting restrictions: restrict by security, restrict by category, restrict by availability, and so on. This is what a filter is for.
What is a filter? A filter restricts results of a query after the Lucene query has been executed, usually based on rules that aren’t directly related to the query. Filters can be adjusted independently of the original query and don’t affect the relative score of a document against another; the ordering defined by the original query is respected. Filters can be applied on top of each other. In Lucene, a filter is very much like a bit mask, which removes part of the results from a query; each Lucene document is represented by a bit, which can be on or off. Figure 8.1 shows how filters selectively remove elements from the result set.