Package org.apache.lucene.monitor
Class TermFilteredPresearcher
- java.lang.Object
-
- org.apache.lucene.monitor.Presearcher
-
- org.apache.lucene.monitor.TermFilteredPresearcher
-
- Direct Known Subclasses:
MultipassTermFilteredPresearcher
public class TermFilteredPresearcher extends Presearcher
Presearcher implementation that uses terms extracted from queries to index them in the Monitor, and builds a disjunction from terms in a document to match them. Handling of queries that do not support term extraction through theQueryVisitor
API can be configured by passing a list ofCustomQueryHandler
implementations. Filtering by additional fields can be configured by passing a set of field names. Documents that contain values in those fields will only be checked againstMonitorQuery
instances that have the same fieldname-value mapping in their metadata.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TermFilteredPresearcher.BytesRefHashIterator
Implements aBytesRefIterator
over aBytesRefHash
protected static interface
TermFilteredPresearcher.DocumentQueryBuilder
Constructs a document disjunction from a set of terms
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
ANYTOKEN
(package private) static java.lang.String
ANYTOKEN_FIELD
static TermWeightor
DEFAULT_WEIGHTOR
The default TermWeightor, weighting by token lengthprivate QueryAnalyzer
extractor
private java.util.Set<java.lang.String>
filterFields
(package private) static FieldType
QUERYFIELDTYPE
private java.util.List<CustomQueryHandler>
queryHandlers
private TermWeightor
weightor
-
Fields inherited from class org.apache.lucene.monitor.Presearcher
NO_FILTERING
-
-
Constructor Summary
Constructors Constructor Description TermFilteredPresearcher()
Creates a new TermFilteredPresearcher using the default term weightingTermFilteredPresearcher(TermWeightor weightor, java.util.List<CustomQueryHandler> customQueryHandlers, java.util.Set<java.lang.String> filterFields)
Creates a new TermFilteredPresearcher
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Query
buildFilterClause(LeafReader reader, java.lang.String field)
private Query
buildFilterFields(LeafReader reader)
Query
buildQuery(LeafReader reader, java.util.function.BiPredicate<java.lang.String,BytesRef> termAcceptor)
Build a query for a Monitor's queryindex from a LeafReader over a set of documents to monitor.protected Document
buildQueryDocument(QueryTree querytree)
Builds aDocument
from the terms extracted from a queryprotected java.util.Map<java.lang.String,BytesRefHash>
collectTerms(QueryTree querytree)
Collects terms from aQueryTree
and maps them per-fieldprotected TermFilteredPresearcher.DocumentQueryBuilder
getQueryBuilder()
Returns aTermFilteredPresearcher.DocumentQueryBuilder
for this presearcherDocument
indexQuery(Query query, java.util.Map<java.lang.String,java.lang.String> metadata)
Build a lucene Document to index the query in a Monitor's queryindex
-
-
-
Field Detail
-
DEFAULT_WEIGHTOR
public static final TermWeightor DEFAULT_WEIGHTOR
The default TermWeightor, weighting by token length
-
extractor
private final QueryAnalyzer extractor
-
weightor
private final TermWeightor weightor
-
filterFields
private final java.util.Set<java.lang.String> filterFields
-
queryHandlers
private final java.util.List<CustomQueryHandler> queryHandlers
-
ANYTOKEN_FIELD
static final java.lang.String ANYTOKEN_FIELD
- See Also:
- Constant Field Values
-
ANYTOKEN
static final java.lang.String ANYTOKEN
- See Also:
- Constant Field Values
-
QUERYFIELDTYPE
static final FieldType QUERYFIELDTYPE
-
-
Constructor Detail
-
TermFilteredPresearcher
public TermFilteredPresearcher()
Creates a new TermFilteredPresearcher using the default term weighting
-
TermFilteredPresearcher
public TermFilteredPresearcher(TermWeightor weightor, java.util.List<CustomQueryHandler> customQueryHandlers, java.util.Set<java.lang.String> filterFields)
Creates a new TermFilteredPresearcher- Parameters:
weightor
- the TermWeightorcustomQueryHandlers
- A list of custom query handlers to extract terms from non-core queriesfilterFields
- A set of fields to filter on
-
-
Method Detail
-
buildQuery
public final Query buildQuery(LeafReader reader, java.util.function.BiPredicate<java.lang.String,BytesRef> termAcceptor)
Description copied from class:Presearcher
Build a query for a Monitor's queryindex from a LeafReader over a set of documents to monitor.- Specified by:
buildQuery
in classPresearcher
- Parameters:
reader
- aLeafReader
over the input documentstermAcceptor
- a predicate indicating if a term should be added to the query- Returns:
- a Query to run over a Monitor's queryindex
-
buildFilterFields
private Query buildFilterFields(LeafReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
buildFilterClause
private Query buildFilterClause(LeafReader reader, java.lang.String field) throws java.io.IOException
- Throws:
java.io.IOException
-
getQueryBuilder
protected TermFilteredPresearcher.DocumentQueryBuilder getQueryBuilder()
Returns aTermFilteredPresearcher.DocumentQueryBuilder
for this presearcher
-
indexQuery
public final Document indexQuery(Query query, java.util.Map<java.lang.String,java.lang.String> metadata)
Description copied from class:Presearcher
Build a lucene Document to index the query in a Monitor's queryindex- Specified by:
indexQuery
in classPresearcher
- Parameters:
query
- the Query to indexmetadata
- a Map of arbitrary query metadata- Returns:
- a lucene Document to add to the queryindex
-
buildQueryDocument
protected Document buildQueryDocument(QueryTree querytree)
Builds aDocument
from the terms extracted from a query
-
collectTerms
protected java.util.Map<java.lang.String,BytesRefHash> collectTerms(QueryTree querytree)
Collects terms from aQueryTree
and maps them per-field
-
-