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 the `QueryVisitor` API can be configured by passing a list of `CustomQueryHandler` 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 against `MonitorQuery` 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 a `BytesRefIterator` over a `BytesRefHash`
`protected static interface`
`TermFilteredPresearcher.DocumentQueryBuilder`
Constructs a document disjunction from a set of terms

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`ANYTOKEN`
`static final String`
`ANYTOKEN_FIELD`
`static final TermWeightor`
`DEFAULT_WEIGHTOR`
The default TermWeightor, weighting by token length

### 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 weighting
`TermFilteredPresearcher(TermWeightor weightor, List<CustomQueryHandler> customQueryHandlers, Set<String> filterFields)`
Creates a new TermFilteredPresearcher

## Method Summary

Modifier and Type
Method
Description
`final Query`
`buildQuery(LeafReader reader, BiPredicate<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 a `Document` from the terms extracted from a query
`protected Map<String,BytesRefHash>`
`collectTerms(QueryTree querytree)`
Collects terms from a `QueryTree` and maps them per-field
`protected TermFilteredPresearcher.DocumentQueryBuilder`
`getQueryBuilder()`
Returns a `TermFilteredPresearcher.DocumentQueryBuilder` for this presearcher
`final Document`
`indexQuery(Query query, Map<String,String> metadata)`
Build a lucene Document to index the query in a Monitor's queryindex

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_WEIGHTOR

public static final TermWeightor DEFAULT_WEIGHTOR
The default TermWeightor, weighting by token length

### ANYTOKEN_FIELD

public static final String ANYTOKEN_FIELD

See Also:
  - Constant Field Values

### ANYTOKEN

public static final String ANYTOKEN

See Also:
  - Constant Field Values

## Constructor Details

### TermFilteredPresearcher

public TermFilteredPresearcher()
Creates a new TermFilteredPresearcher using the default term weighting

### TermFilteredPresearcher

public TermFilteredPresearcher(TermWeightor weightor, List<CustomQueryHandler> customQueryHandlers, Set<String> filterFields)
Creates a new TermFilteredPresearcher

Parameters:
  `weightor` - the TermWeightor
  `customQueryHandlers` - A list of custom query handlers to extract terms from non-core queries
  `filterFields` - A set of fields to filter on

## Method Details

### buildQuery

public final Query buildQuery(LeafReader reader, BiPredicate<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 class `Presearcher`
Parameters:
  `reader` - a `LeafReader` over the input documents
  `termAcceptor` - a predicate indicating if a term should be added to the query
Returns:
  a Query to run over a Monitor's queryindex

### getQueryBuilder

protected TermFilteredPresearcher.DocumentQueryBuilder getQueryBuilder()
Returns a `TermFilteredPresearcher.DocumentQueryBuilder` for this presearcher

### indexQuery

public final Document indexQuery(Query query, Map<String,String> metadata)
Description copied from class: `Presearcher`
Build a lucene Document to index the query in a Monitor's queryindex

Specified by:
  `indexQuery` in class `Presearcher`
Parameters:
  `query` - the Query to index
  `metadata` - a Map of arbitrary query metadata
Returns:
  a lucene Document to add to the queryindex

### buildQueryDocument

protected Document buildQueryDocument(QueryTree querytree)
Builds a `Document` from the terms extracted from a query

### collectTerms

protected Map<String,BytesRefHash> collectTerms(QueryTree querytree)
Collects terms from a `QueryTree` and maps them per-field