Class HighlightBuilder
- java.lang.Object
-
- org.elasticsearch.search.fetch.subphase.highlight.AbstractHighlighterBuilder<HighlightBuilder>
-
- org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder
-
- All Implemented Interfaces:
Writeable,ToXContent,ToXContentObject,Rewriteable<HighlightBuilder>
public class HighlightBuilder extends AbstractHighlighterBuilder<HighlightBuilder>
A builder for search highlighting. Settings can control how large fields are summarized to show only selected snippets ("fragments") containing search terms.- See Also:
SearchSourceBuilder.highlight()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHighlightBuilder.BoundaryScannerTypestatic classHighlightBuilder.Fieldstatic classHighlightBuilder.Order-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_ENCODERthe default encoder settingstatic booleanDEFAULT_FORCE_SOURCEdefault for whether to highlight fields based on the source even if stored separatelystatic intDEFAULT_FRAGMENT_CHAR_SIZEthe default number of fragments size in charactersstatic booleanDEFAULT_HIGHLIGHT_FILTERdefault for whetherfvhshould provide highlighting on filter clausesstatic intDEFAULT_NO_MATCH_SIZEdefault for fragment size when there are no matchesstatic intDEFAULT_NUMBER_OF_FRAGMENTSthe default number of fragments for highlightingstatic intDEFAULT_PHRASE_LIMITdefault for the maximum number of phrases the fvh will considerstatic booleanDEFAULT_REQUIRE_FIELD_MATCHdefault for whether a field should be highlighted only if a query matches that fieldstatic booleanDEFAULT_SCORE_ORDEREDdefault for highlight fragments being ordered by scorestatic java.lang.String[]DEFAULT_STYLED_POST_TAGSthe default closing tags whentag_schema = "styled"static java.lang.String[]DEFAULT_STYLED_PRE_TAGthe default opening tags whentag_schema = "styled"-
Fields inherited from class org.elasticsearch.search.fetch.subphase.highlight.AbstractHighlighterBuilder
BOUNDARY_CHARS_FIELD, BOUNDARY_MAX_SCAN_FIELD, BOUNDARY_SCANNER_FIELD, BOUNDARY_SCANNER_LOCALE_FIELD, boundaryChars, boundaryMaxScan, boundaryScannerLocale, boundaryScannerType, ENCODER_FIELD, FIELDS_FIELD, FORCE_SOURCE_FIELD, forceSource, FRAGMENT_OFFSET_FIELD, FRAGMENT_SIZE_FIELD, fragmenter, FRAGMENTER_FIELD, fragmentSize, HIGHLIGHT_FILTER_FIELD, HIGHLIGHT_QUERY_FIELD, highlighterType, highlightFilter, highlightQuery, MATCHED_FIELDS_FIELD, NO_MATCH_SIZE_FIELD, noMatchSize, NUMBER_OF_FRAGMENTS_FIELD, numOfFragments, options, OPTIONS_FIELD, order, ORDER_FIELD, PHRASE_LIMIT_FIELD, phraseLimit, POST_TAGS_FIELD, postTags, PRE_TAGS_FIELD, preTags, REQUIRE_FIELD_MATCH_FIELD, requireFieldMatch, TYPE_FIELD
-
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description HighlightBuilder()HighlightBuilder(StreamInput in)Read from a stream.HighlightBuilder(HighlightBuilder template, QueryBuilder highlightQuery, java.util.List<HighlightBuilder.Field> fields)
-
Method Summary
Modifier and Type Method Description SearchContextHighlightbuild(QueryShardContext context)protected booleandoEquals(HighlightBuilder other)fields only present in subclass should be checked for equality in the implementationprotected intdoHashCode()fields only present in subclass should contribute to hashCode in the implementationprotected voiddoWriteTo(StreamOutput out)java.lang.Stringencoder()Getter forencoder(String)HighlightBuilderencoder(java.lang.String encoder)Set encoder for the highlighting arehtmlanddefault.HighlightBuilderfield(java.lang.String name)Adds a field to be highlighted with default fragment size of 100 characters, and default number of fragments of 5 using the default encoderHighlightBuilderfield(java.lang.String name, int fragmentSize)Adds a field to be highlighted with a provided fragment size (in characters), and default number of fragments of 5.HighlightBuilderfield(java.lang.String name, int fragmentSize, int numberOfFragments)Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.HighlightBuilderfield(java.lang.String name, int fragmentSize, int numberOfFragments, int fragmentOffset)Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.HighlightBuilderfield(HighlightBuilder.Field field)java.util.List<HighlightBuilder.Field>fields()static HighlightBuilderfromXContent(XContentParser p)voidinnerXContent(XContentBuilder builder)HighlightBuilderrewrite(QueryRewriteContext ctx)Rewrites this instance based on the provided context.HighlightBuildertagsSchema(java.lang.String schemaName)Set a tag scheme that encapsulates a built in pre and post tags.XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)java.lang.BooleanuseExplicitFieldOrder()Gets value set withuseExplicitFieldOrder(boolean)HighlightBuilderuseExplicitFieldOrder(boolean useExplicitFieldOrder)Send the fields to be highlighted using a syntax that is specific about the order in which they should be highlighted.-
Methods inherited from class org.elasticsearch.search.fetch.subphase.highlight.AbstractHighlighterBuilder
boundaryChars, boundaryChars, boundaryMaxScan, boundaryMaxScan, boundaryScannerLocale, boundaryScannerLocale, boundaryScannerType, boundaryScannerType, boundaryScannerType, equals, forceSource, forceSource, fragmenter, fragmenter, fragmentSize, fragmentSize, hashCode, highlighterType, highlighterType, highlightFilter, highlightFilter, highlightQuery, highlightQuery, noMatchSize, noMatchSize, numOfFragments, numOfFragments, options, options, order, order, order, phraseLimit, phraseLimit, postTags, postTags, preTags, preTags, requireFieldMatch, requireFieldMatch, toString, writeTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
DEFAULT_FORCE_SOURCE
public static final boolean DEFAULT_FORCE_SOURCE
default for whether to highlight fields based on the source even if stored separately- See Also:
- Constant Field Values
-
DEFAULT_REQUIRE_FIELD_MATCH
public static final boolean DEFAULT_REQUIRE_FIELD_MATCH
default for whether a field should be highlighted only if a query matches that field- See Also:
- Constant Field Values
-
DEFAULT_HIGHLIGHT_FILTER
public static final boolean DEFAULT_HIGHLIGHT_FILTER
default for whetherfvhshould provide highlighting on filter clauses- See Also:
- Constant Field Values
-
DEFAULT_SCORE_ORDERED
public static final boolean DEFAULT_SCORE_ORDERED
default for highlight fragments being ordered by score- See Also:
- Constant Field Values
-
DEFAULT_ENCODER
public static final java.lang.String DEFAULT_ENCODER
the default encoder setting- See Also:
- Constant Field Values
-
DEFAULT_PHRASE_LIMIT
public static final int DEFAULT_PHRASE_LIMIT
default for the maximum number of phrases the fvh will consider- See Also:
- Constant Field Values
-
DEFAULT_NO_MATCH_SIZE
public static final int DEFAULT_NO_MATCH_SIZE
default for fragment size when there are no matches- See Also:
- Constant Field Values
-
DEFAULT_NUMBER_OF_FRAGMENTS
public static final int DEFAULT_NUMBER_OF_FRAGMENTS
the default number of fragments for highlighting- See Also:
- Constant Field Values
-
DEFAULT_FRAGMENT_CHAR_SIZE
public static final int DEFAULT_FRAGMENT_CHAR_SIZE
the default number of fragments size in characters- See Also:
- Constant Field Values
-
DEFAULT_STYLED_PRE_TAG
public static final java.lang.String[] DEFAULT_STYLED_PRE_TAG
the default opening tags whentag_schema = "styled"
-
DEFAULT_STYLED_POST_TAGS
public static final java.lang.String[] DEFAULT_STYLED_POST_TAGS
the default closing tags whentag_schema = "styled"
-
-
Constructor Detail
-
HighlightBuilder
public HighlightBuilder()
-
HighlightBuilder
public HighlightBuilder(HighlightBuilder template, QueryBuilder highlightQuery, java.util.List<HighlightBuilder.Field> fields)
-
HighlightBuilder
public HighlightBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
doWriteTo
protected void doWriteTo(StreamOutput out) throws java.io.IOException
- Specified by:
doWriteToin classAbstractHighlighterBuilder<HighlightBuilder>- Throws:
java.io.IOException
-
field
public HighlightBuilder field(java.lang.String name)
Adds a field to be highlighted with default fragment size of 100 characters, and default number of fragments of 5 using the default encoder- Parameters:
name- The field to highlight
-
field
public HighlightBuilder field(java.lang.String name, int fragmentSize)
Adds a field to be highlighted with a provided fragment size (in characters), and default number of fragments of 5.- Parameters:
name- The field to highlightfragmentSize- The size of a fragment in characters
-
field
public HighlightBuilder field(java.lang.String name, int fragmentSize, int numberOfFragments)
Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.- Parameters:
name- The field to highlightfragmentSize- The size of a fragment in charactersnumberOfFragments- The (maximum) number of fragments
-
field
public HighlightBuilder field(java.lang.String name, int fragmentSize, int numberOfFragments, int fragmentOffset)
Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.- Parameters:
name- The field to highlightfragmentSize- The size of a fragment in charactersnumberOfFragments- The (maximum) number of fragmentsfragmentOffset- The offset from the start of the fragment to the start of the highlight
-
field
public HighlightBuilder field(HighlightBuilder.Field field)
-
fields
public java.util.List<HighlightBuilder.Field> fields()
-
tagsSchema
public HighlightBuilder tagsSchema(java.lang.String schemaName)
Set a tag scheme that encapsulates a built in pre and post tags. The allowed schemes arestyledanddefault.- Parameters:
schemaName- The tag scheme name
-
encoder
public HighlightBuilder encoder(java.lang.String encoder)
Set encoder for the highlighting arehtmlanddefault.- Parameters:
encoder- name
-
encoder
public java.lang.String encoder()
Getter forencoder(String)
-
useExplicitFieldOrder
public HighlightBuilder useExplicitFieldOrder(boolean useExplicitFieldOrder)
Send the fields to be highlighted using a syntax that is specific about the order in which they should be highlighted.- Returns:
- this for chaining
-
useExplicitFieldOrder
public java.lang.Boolean useExplicitFieldOrder()
Gets value set withuseExplicitFieldOrder(boolean)
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContentin interfaceToXContent- Overrides:
toXContentin classAbstractHighlighterBuilder<HighlightBuilder>- Throws:
java.io.IOException
-
fromXContent
public static HighlightBuilder fromXContent(XContentParser p)
-
build
public SearchContextHighlight build(QueryShardContext context) throws java.io.IOException
- Throws:
java.io.IOException
-
innerXContent
public void innerXContent(XContentBuilder builder) throws java.io.IOException
- Specified by:
innerXContentin classAbstractHighlighterBuilder<HighlightBuilder>- Throws:
java.io.IOException
-
doHashCode
protected int doHashCode()
Description copied from class:AbstractHighlighterBuilderfields only present in subclass should contribute to hashCode in the implementation- Specified by:
doHashCodein classAbstractHighlighterBuilder<HighlightBuilder>
-
doEquals
protected boolean doEquals(HighlightBuilder other)
Description copied from class:AbstractHighlighterBuilderfields only present in subclass should be checked for equality in the implementation- Specified by:
doEqualsin classAbstractHighlighterBuilder<HighlightBuilder>
-
rewrite
public HighlightBuilder rewrite(QueryRewriteContext ctx) throws java.io.IOException
Description copied from interface:RewriteableRewrites this instance based on the provided context. The returned objects will be the same instance as this if no changes during the rewrite were applied.- Throws:
java.io.IOException
-
-