public class PhraseHelper extends Object
FieldOffsetStrategy
with position sensitive queries (e.g. highlight phrases correctly).
This is a stateful class holding information about the query, but it can (and is) re-used across highlighting
documents. Despite this state, it's immutable after construction.Modifier and Type | Field and Description |
---|---|
static PhraseHelper |
NONE |
Constructor and Description |
---|
PhraseHelper(Query query,
String field,
Predicate<String> fieldMatcher,
Function<SpanQuery,Boolean> rewriteQueryPred,
Function<Query,Collection<Query>> preExtractRewriteFunction,
boolean ignoreQueriesNeedingRewrite)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
createOffsetsEnumsForSpans(LeafReader leafReader,
int docId,
List<OffsetsEnum> results)
Given the internal SpanQueries, produce a number of OffsetsEnum into the
results param. |
BytesRef[] |
getAllPositionInsensitiveTerms()
Returns the terms that are position-insensitive (sorted).
|
Set<SpanQuery> |
getSpanQueries() |
boolean |
hasPositionSensitivity()
If there is no position sensitivity then use of the instance of this class can be ignored.
|
boolean |
willRewrite()
Rewrite is needed for handling a
SpanMultiTermQueryWrapper (MTQ / wildcards) or some
custom things. |
public static final PhraseHelper NONE
public PhraseHelper(Query query, String field, Predicate<String> fieldMatcher, Function<SpanQuery,Boolean> rewriteQueryPred, Function<Query,Collection<Query>> preExtractRewriteFunction, boolean ignoreQueriesNeedingRewrite)
rewriteQueryPred
is an extension hook to override the default choice of
WeightedSpanTermExtractor.mustRewriteQuery(SpanQuery)
. By default unknown query types are rewritten,
so use this to return Boolean.FALSE
if you know the query doesn't need to be rewritten.
Similarly, preExtractRewriteFunction
is also an extension hook for extract to allow different queries
to be set before the WeightedSpanTermExtractor
's extraction is invoked.
ignoreQueriesNeedingRewrite
effectively ignores any query clause that needs to be "rewritten", which is
usually limited to just a SpanMultiTermQueryWrapper
but could be other custom ones.
fieldMatcher
The field name predicate to use for extracting the query part that must be highlighted.public boolean hasPositionSensitivity()
public boolean willRewrite()
SpanMultiTermQueryWrapper
(MTQ / wildcards) or some
custom things. When true, the resulting term list will probably be different than what it was known
to be initially.public BytesRef[] getAllPositionInsensitiveTerms()
public void createOffsetsEnumsForSpans(LeafReader leafReader, int docId, List<OffsetsEnum> results) throws IOException
results
param.IOException
Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.