![]() However, this scenario is oversimplified for most needs the ways that documents are associated with roles may be quite a bit more dynamic. If your security requirements are this straightforward, where documents can be associated with users or roles during indexing, using a QueryWrapperFilter will work nicely. Listing 1: Using RangeFilter to filter by date range public class FilterTest extends LiaTestCase #1 This is a general TermQuery for info.#2 All documents containing info are returned.#3 Here, the filter constrains document searches to only owned by "jake".#4 Only Jake's document is returned, using the same info TermQuery. We test the date RangeFilter by using an all-inclusive query, which by itself returns all documents. Our book data indexes the last modified date of each book data file as a modified field, indexed as with _ANALYZED and. Having a date field, you filter as shown in testDateFilter() in Listing 1. If the field is simply textual, for example last names, then you can filter for all names within a certain alphabetic range such as M to Q. If it's an integer field, you can filter by numeric range. If the field is a date field, then you get a date range filter. This is actually very useful, depending on the original type of the field. RangeFilter filters on a range of terms in a specific field. Now let's discuss each of the built-in filters as well as the BooleanQuery alternative. ![]() CachingWrapperFilter is a decorator over another filter, caching its results to increase performance when used again.īefore you get concerned about mentions of caching results, rest assured that it's done with a tiny data structure (a BitSet) where each bit position represents a document.Ĭonsider, also, the alternative to using a filter: aggregating required clauses in a BooleanQuery.QueryWrapperFilter uses the results of query as the searchable document space for a new query.RangeFilter matches only documents containing terms within a specified range of terms.PrefixFilter matches only documents containing terms in a specific field with a specific prefix.There are several built-in Filter implementations: You can filter any Lucene search, using the overloaded search methods that accept a Filter parameter. ![]() A security filter is a powerful example, allowing users to only see search results of documents they own even if their query technically matches other documents that are off limits we provide an example of a security filter in the section "Security filters". They can be used to implement search-within-search features to successively search within a previous set of results or to constrain the document search space for security or external data reasons. įiltering is a mechanism of narrowing the search space, allowing only a subset of the documents to be considered as possible hits. For the book's table of contents, the Author Forum, and other resources,go to. Filters constrain document search space,regardless of the query. This article addresses using filters in Lucene.Some projects need more than the basic searching mechanisms. This article is taken from Chapter 5 of Lucene in Action, 2nd Edition, by Erik Hatcher,Otis Gospodnetić, and Michael McCandless.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |