Class PhraseHelper
- java.lang.Object
-
- org.apache.lucene.search.uhighlight.PhraseHelper
-
public class PhraseHelper extends java.lang.ObjectHelps theFieldOffsetStrategywith 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPhraseHelper.OffsetSpanCollectorprivate static classPhraseHelper.SingleFieldWithOffsetsFilterLeafReaderNeeded to support the ability to highlight a query irrespective of the field a query refers to (aka requireFieldMatch=false).private static classPhraseHelper.SpanCollectedOffsetsEnum
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Predicate<java.lang.String>fieldMatcherprivate java.lang.StringfieldNamestatic PhraseHelperNONEprivate java.util.Set<BytesRef>positionInsensitiveTermsprivate java.util.Set<SpanQuery>spanQueriesprivate booleanwillRewrite
-
Constructor Summary
Constructors Constructor Description PhraseHelper(Query query, java.lang.String field, java.util.function.Predicate<java.lang.String> fieldMatcher, java.util.function.Function<SpanQuery,java.lang.Boolean> rewriteQueryPred, java.util.function.Function<Query,java.util.Collection<Query>> preExtractRewriteFunction, boolean ignoreQueriesNeedingRewrite)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateOffsetsEnumsForSpans(LeafReader leafReader, int docId, java.util.List<OffsetsEnum> results)Given the internal SpanQueries, produce a number of OffsetsEnum into theresultsparam.BytesRef[]getAllPositionInsensitiveTerms()Returns the terms that are position-insensitive (sorted).java.util.Set<SpanQuery>getSpanQueries()booleanhasPositionSensitivity()If there is no position sensitivity then use of the instance of this class can be ignored.booleanwillRewrite()Rewrite is needed for handling aSpanMultiTermQueryWrapper(MTQ / wildcards) or some custom things.
-
-
-
Field Detail
-
NONE
public static final PhraseHelper NONE
-
fieldName
private final java.lang.String fieldName
-
positionInsensitiveTerms
private final java.util.Set<BytesRef> positionInsensitiveTerms
-
spanQueries
private final java.util.Set<SpanQuery> spanQueries
-
willRewrite
private final boolean willRewrite
-
fieldMatcher
private final java.util.function.Predicate<java.lang.String> fieldMatcher
-
-
Constructor Detail
-
PhraseHelper
public PhraseHelper(Query query, java.lang.String field, java.util.function.Predicate<java.lang.String> fieldMatcher, java.util.function.Function<SpanQuery,java.lang.Boolean> rewriteQueryPred, java.util.function.Function<Query,java.util.Collection<Query>> preExtractRewriteFunction, boolean ignoreQueriesNeedingRewrite)
Constructor.rewriteQueryPredis an extension hook to override the default choice ofWeightedSpanTermExtractor.mustRewriteQuery(SpanQuery). By default unknown query types are rewritten, so use this to returnBoolean.FALSEif you know the query doesn't need to be rewritten. Similarly,preExtractRewriteFunctionis also an extension hook for extract to allow different queries to be set before theWeightedSpanTermExtractor's extraction is invoked.ignoreQueriesNeedingRewriteeffectively ignores any query clause that needs to be "rewritten", which is usually limited to just aSpanMultiTermQueryWrapperbut could be other custom ones.fieldMatcherThe field name predicate to use for extracting the query part that must be highlighted.
-
-
Method Detail
-
getSpanQueries
public java.util.Set<SpanQuery> getSpanQueries()
-
hasPositionSensitivity
public boolean hasPositionSensitivity()
If there is no position sensitivity then use of the instance of this class can be ignored.
-
willRewrite
public boolean willRewrite()
Rewrite is needed for handling aSpanMultiTermQueryWrapper(MTQ / wildcards) or some custom things. When true, the resulting term list will probably be different than what it was known to be initially.
-
getAllPositionInsensitiveTerms
public BytesRef[] getAllPositionInsensitiveTerms()
Returns the terms that are position-insensitive (sorted).
-
createOffsetsEnumsForSpans
public void createOffsetsEnumsForSpans(LeafReader leafReader, int docId, java.util.List<OffsetsEnum> results) throws java.io.IOException
Given the internal SpanQueries, produce a number of OffsetsEnum into theresultsparam.- Throws:
java.io.IOException
-
-