Class PhraseHelper
- java.lang.Object
-
- org.apache.lucene.search.uhighlight.PhraseHelper
-
public class PhraseHelper extends Object
Helps 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.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Field Summary
Fields Modifier and Type Field Description static PhraseHelperNONE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateOffsetsEnumsForSpans(LeafReader leafReader, int docId, List<OffsetsEnum> results)Given the internal SpanQueries, produce a number of OffsetsEnum into theresultsparam.BytesRef[]getAllPositionInsensitiveTerms()Returns the terms that are position-insensitive (sorted).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
-
-
Constructor Detail
-
PhraseHelper
public PhraseHelper(Query query, String field, Predicate<String> fieldMatcher, Function<SpanQuery,Boolean> rewriteQueryPred, Function<Query,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
-
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, List<OffsetsEnum> results) throws IOException
Given the internal SpanQueries, produce a number of OffsetsEnum into theresultsparam.- Throws:
IOException
-
-