org.apache.solr.highlight

## Class DefaultSolrHighlighter

- java.lang.Object
- - org.apache.solr.highlight.SolrHighlighter
  - - org.apache.solr.highlight.DefaultSolrHighlighter

- All Implemented Interfaces:
    PluginInfoInitialized

      public class DefaultSolrHighlighter
      extends SolrHighlighter
      implements PluginInfoInitialized

  Since:
    solr 1.3

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `DefaultSolrHighlighter.FvhContainer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<String,SolrBoundaryScanner>` | `boundaryScanners`
    `protected Map<String,SolrEncoder>` | `encoders`
    `protected Map<String,SolrFormatter>` | `formatters`
    `protected Map<String,SolrFragListBuilder>` | `fragListBuilders`
    `protected Map<String,SolrFragmenter>` | `fragmenters`
    `protected Map<String,SolrFragmentsBuilder>` | `fragmentsBuilders`
    `protected SolrCore` | `solrCore`

    - ### Fields inherited from class org.apache.solr.highlight.SolrHighlighter

      `DEFAULT_PHRASE_LIMIT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultSolrHighlighter(SolrCore solrCore)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Object` | `alternateField(Document doc, int docId, String fieldName, DefaultSolrHighlighter.FvhContainer fvhContainer, Query query, IndexReader reader, SolrQueryRequest req)` Returns the alternate highlight object for this field -- a String[] by default.
    `protected TokenStream` | `createAnalyzerTStream(SchemaField schemaField, String docText)`
    `NamedList<Object>` | `doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields)` Generates a list of Highlighted query fragments for each item in a list of documents, or returns null if highlighting is disabled.
    `protected Object` | `doHighlightingByFastVectorHighlighter(Document doc, int docId, SchemaField schemaField, DefaultSolrHighlighter.FvhContainer fvhContainer, IndexReader reader, SolrQueryRequest req)` Highlights and returns the highlight object for this field -- a String[] by default.
    `protected Object` | `doHighlightingByHighlighter(Document doc, int docId, SchemaField schemaField, Query query, IndexReader reader, SolrQueryRequest req)` Highlights and returns the highlight object for this field -- a String[] by default.
    `protected Object` | `doHighlightingOfField(Document doc, int docId, SchemaField schemaField, DefaultSolrHighlighter.FvhContainer fvhContainer, Query query, IndexReader reader, SolrQueryRequest req, SolrParams params)`
    `protected BoundaryScanner` | `getBoundaryScanner(String fieldName, SolrParams params)`
    `protected Set<String>` | `getDocPrefetchFieldNames(String[] hlFieldNames, SolrQueryRequest req)` Returns the field names to be passed to `SolrIndexSearcher.doc(int, Set)`.
    `protected Encoder` | `getEncoder(String fieldName, SolrParams params)` Return an `Encoder` appropriate for this field.
    `protected List<String>` | `getFieldValues(Document doc, String fieldName, int maxValues, int maxCharsToAnalyze, SolrQueryRequest req)` Fetches field values to highlight.
    `protected Formatter` | `getFormatter(String fieldName, SolrParams params)` Return a `Formatter` appropriate for this field.
    `protected FragListBuilder` | `getFragListBuilder(String fieldName, SolrParams params)`
    `protected Fragmenter` | `getFragmenter(String fieldName, SolrParams params)` Return a `Fragmenter` appropriate for this field.
    `protected FragmentsBuilder` | `getFragmentsBuilder(String fieldName, SolrParams params)`
    `protected Highlighter` | `getHighlighter(Query query, String fieldName, SolrQueryRequest request)` Return a `Highlighter` appropriate for this field.
    `protected int` | `getMaxSnippets(String fieldName, SolrParams params)` Return the max number of snippets for this field.
    `protected Highlighter` | `getPhraseHighlighter(Query query, String fieldName, SolrQueryRequest request, TokenStream tokenStream)` Return a phrase `Highlighter` appropriate for this field.
    `protected Scorer` | `getQueryScorer(Query query, String fieldName, SolrQueryRequest request)` Return a `Scorer` suitable for this Query and field.
    `protected Object` | `getResponseForFragments(List<TextFragment> frags, SolrQueryRequest req)` Given the fragments, return the result to be put in the field `NamedList`.
    `protected SolrFragmentsBuilder` | `getSolrFragmentsBuilder(String fieldName, SolrParams params)`
    `protected QueryScorer` | `getSpanQueryScorer(Query query, String fieldName, TokenStream tokenStream, SolrQueryRequest request)` Return a `QueryScorer` suitable for this Query and field.
    `void` | `init(PluginInfo info)`
    `protected boolean` | `isMergeContiguousFragments(String fieldName, SolrParams params)` Return whether adjacent fragments should be merged.
    `protected boolean` | `useFastVectorHighlighter(SolrParams params, SchemaField schemaField)` Determines if we should use the FastVectorHighlighter for this field.

    - ### Methods inherited from class org.apache.solr.highlight.SolrHighlighter

      `emptyArray, getHighlightFields, isHighlightingEnabled`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### solrCore

          protected final SolrCore solrCore

    - #### formatters

          protected final Map<String,SolrFormatter> formatters

    - #### encoders

          protected final Map<String,SolrEncoder> encoders

    - #### fragmenters

          protected final Map<String,SolrFragmenter> fragmenters

    - #### fragListBuilders

          protected final Map<String,SolrFragListBuilder> fragListBuilders

    - #### fragmentsBuilders

          protected final Map<String,SolrFragmentsBuilder> fragmentsBuilders

    - #### boundaryScanners

          protected final Map<String,SolrBoundaryScanner> boundaryScanners

  - ### Constructor Detail

    - #### DefaultSolrHighlighter

          public DefaultSolrHighlighter(SolrCore solrCore)

  - ### Method Detail

    - #### init

          public void init(PluginInfo info)

      Specified by:
        `init` in interface `PluginInfoInitialized`

    - #### getPhraseHighlighter

          protected Highlighter getPhraseHighlighter(Query query,
                                                     String fieldName,
                                                     SolrQueryRequest request,
                                                     TokenStream tokenStream)
                                              throws IOException

      Return a phrase `Highlighter` appropriate for this field.
      Parameters:
        `query` - The current Query
        `fieldName` - The name of the field
        `request` - The current SolrQueryRequest
        `tokenStream` - document text tokenStream that implements reset() efficiently (e.g. CachingTokenFilter). If it's used, call reset() first.
      Throws:
        `IOException` - If there is a low-level I/O error.

    - #### getHighlighter

          protected Highlighter getHighlighter(Query query,
                                               String fieldName,
                                               SolrQueryRequest request)

      Return a `Highlighter` appropriate for this field.
      Parameters:
        `query` - The current Query
        `fieldName` - The name of the field
        `request` - The current SolrQueryRequest

    - #### getSpanQueryScorer

          protected QueryScorer getSpanQueryScorer(Query query,
                                                   String fieldName,
                                                   TokenStream tokenStream,
                                                   SolrQueryRequest request)

      Return a `QueryScorer` suitable for this Query and field.
      Parameters:
        `query` - The current query
        `tokenStream` - document text tokenStream that implements reset() efficiently (e.g. CachingTokenFilter). If it's used, call reset() first.
        `fieldName` - The name of the field
        `request` - The SolrQueryRequest

    - #### getQueryScorer

          protected Scorer getQueryScorer(Query query,
                                          String fieldName,
                                          SolrQueryRequest request)

      Return a `Scorer` suitable for this Query and field.
      Parameters:
        `query` - The current query
        `fieldName` - The name of the field
        `request` - The SolrQueryRequest

    - #### getMaxSnippets

          protected int getMaxSnippets(String fieldName,
                                       SolrParams params)

      Return the max number of snippets for this field. If this has not been configured for this field, fall back to the configured default or the solr default.
      Parameters:
        `fieldName` - The name of the field
        `params` - The params controlling Highlighting

    - #### isMergeContiguousFragments

          protected boolean isMergeContiguousFragments(String fieldName,
                                                       SolrParams params)

      Return whether adjacent fragments should be merged.
      Parameters:
        `fieldName` - The name of the field
        `params` - The params controlling Highlighting

    - #### getFormatter

          protected Formatter getFormatter(String fieldName,
                                           SolrParams params)

      Return a `Formatter` appropriate for this field. If a formatter has not been configured for this field, fall back to the configured default or the solr default (`SimpleHTMLFormatter`).
      Parameters:
        `fieldName` - The name of the field
        `params` - The params controlling Highlighting
      Returns:
        An appropriate `Formatter`.

    - #### getEncoder

          protected Encoder getEncoder(String fieldName,
                                       SolrParams params)

      Return an `Encoder` appropriate for this field. If an encoder has not been configured for this field, fall back to the configured default or the solr default (`DefaultEncoder`).
      Parameters:
        `fieldName` - The name of the field
        `params` - The params controlling Highlighting
      Returns:
        An appropriate `Encoder`.

    - #### getFragmenter

          protected Fragmenter getFragmenter(String fieldName,
                                             SolrParams params)

      Return a `Fragmenter` appropriate for this field. If a fragmenter has not been configured for this field, fall back to the configured default or the solr default (`GapFragmenter`).
      Parameters:
        `fieldName` - The name of the field
        `params` - The params controlling Highlighting
      Returns:
        An appropriate `Fragmenter`.

    - #### getFragListBuilder

          protected FragListBuilder getFragListBuilder(String fieldName,
                                                       SolrParams params)

    - #### getFragmentsBuilder

          protected FragmentsBuilder getFragmentsBuilder(String fieldName,
                                                         SolrParams params)

    - #### getSolrFragmentsBuilder

          protected SolrFragmentsBuilder getSolrFragmentsBuilder(String fieldName,
                                                                 SolrParams params)

    - #### getBoundaryScanner

          protected BoundaryScanner getBoundaryScanner(String fieldName,
                                                       SolrParams params)

    - #### doHighlighting

          public NamedList<Object> doHighlighting(DocList docs,
                                                  Query query,
                                                  SolrQueryRequest req,
                                                  String[] defaultFields)
                                           throws IOException

      Generates a list of Highlighted query fragments for each item in a list of documents, or returns null if highlighting is disabled.
      Specified by:
        `doHighlighting` in class `SolrHighlighter`
      Parameters:
        `docs` - query results
        `query` - the query
        `req` - the current request
        `defaultFields` - default list of fields to summarize
      Returns:
        NamedList containing a NamedList for each document, which in turns contains sets (field, summary) pairs.
      Throws:
        `IOException`

    - #### doHighlightingOfField

          protected Object doHighlightingOfField(Document doc,
                                                 int docId,
                                                 SchemaField schemaField,
                                                 DefaultSolrHighlighter.FvhContainer fvhContainer,
                                                 Query query,
                                                 IndexReader reader,
                                                 SolrQueryRequest req,
                                                 SolrParams params)
                                          throws IOException

      Throws:
        `IOException`

    - #### getDocPrefetchFieldNames

          protected Set<String> getDocPrefetchFieldNames(String[] hlFieldNames,
                                                         SolrQueryRequest req)

      Returns the field names to be passed to `SolrIndexSearcher.doc(int, Set)`. Subclasses might over-ride to include fields in search-results and other stored field values needed so as to avoid the possibility of extra trips to disk. The uniqueKey will be added after if the result isn't null.

    - #### useFastVectorHighlighter

          protected boolean useFastVectorHighlighter(SolrParams params,
                                                     SchemaField schemaField)

      Determines if we should use the FastVectorHighlighter for this field.

    - #### doHighlightingByFastVectorHighlighter

          protected Object doHighlightingByFastVectorHighlighter(Document doc,
                                                                 int docId,
                                                                 SchemaField schemaField,
                                                                 DefaultSolrHighlighter.FvhContainer fvhContainer,
                                                                 IndexReader reader,
                                                                 SolrQueryRequest req)
                                                          throws IOException

      Highlights and returns the highlight object for this field -- a String[] by default. Null if none.
      Throws:
        `IOException`

    - #### doHighlightingByHighlighter

          protected Object doHighlightingByHighlighter(Document doc,
                                                       int docId,
                                                       SchemaField schemaField,
                                                       Query query,
                                                       IndexReader reader,
                                                       SolrQueryRequest req)
                                                throws IOException

      Highlights and returns the highlight object for this field -- a String[] by default. Null if none.
      Throws:
        `IOException`

    - #### getFieldValues

          protected List<String> getFieldValues(Document doc,
                                                String fieldName,
                                                int maxValues,
                                                int maxCharsToAnalyze,
                                                SolrQueryRequest req)

      Fetches field values to highlight. If the field value should come from an atypical place (or another aliased field name, then a subclass could override to implement that.

    - #### getResponseForFragments

          protected Object getResponseForFragments(List<TextFragment> frags,
                                                   SolrQueryRequest req)

      Given the fragments, return the result to be put in the field `NamedList`. This is an extension point to allow adding other metadata like the absolute offsets or scores.

    - #### alternateField

          protected Object alternateField(Document doc,
                                          int docId,
                                          String fieldName,
                                          DefaultSolrHighlighter.FvhContainer fvhContainer,
                                          Query query,
                                          IndexReader reader,
                                          SolrQueryRequest req)
                                   throws IOException

      Returns the alternate highlight object for this field -- a String[] by default. Null if none.
      Throws:
        `IOException`

    - #### createAnalyzerTStream

          protected TokenStream createAnalyzerTStream(SchemaField schemaField,
                                                      String docText)
                                               throws IOException

      Throws:
        `IOException`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.