public class PhraseHelper extends Object
FieldOffsetStrategy
with strict position highlighting (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. The approach taken in this class is very similar
to the standard Highlighter's WeightedSpanTermExtractor
which is in fact re-used here. However, we ought to
completely rewrite it to use the SpanCollector interface to collect offsets directly. We'll get better
phrase accuracy.Modifier and Type | Field and Description |
---|---|
static PhraseHelper |
NONE |
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.Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.