org.apache.solr.highlight

## Class PostingsSolrHighlighter

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

- All Implemented Interfaces:
    PluginInfoInitialized

      public class PostingsSolrHighlighter
      extends SolrHighlighter
      implements PluginInfoInitialized

  Highlighter impl that uses `PostingsHighlighter`

  Example configuration:

         <requestHandler name="standard" class="solr.StandardRequestHandler">
           <lst name="defaults">
             <int name="hl.snippets">1</int>
             <str name="hl.tag.pre">&lt;em&gt;</str>
             <str name="hl.tag.post">&lt;/em&gt;</str>
             <str name="hl.tag.ellipsis">... </str>
             <bool name="hl.defaultSummary">true</bool>
             <str name="hl.encoder">simple</str>
             <float name="hl.score.k1">1.2</float>
             <float name="hl.score.b">0.75</float>
             <float name="hl.score.pivot">87</float>
             <str name="hl.bs.language"></str>
             <str name="hl.bs.country"></str>
             <str name="hl.bs.variant"></str>
             <str name="hl.bs.type">SENTENCE</str>
             <int name="hl.maxAnalyzedChars">10000</int>
             <str name="hl.multiValuedSeparatorChar"> </str>
             <bool name="hl.highlightMultiTerm">false</bool>
           </lst>
         </requestHandler>

  ...

         <searchComponent class="solr.HighlightComponent" name="highlight">
           <highlighting class="org.apache.solr.highlight.PostingsSolrHighlighter"/>
         </searchComponent>

  Notes:

  - fields to highlight must be configured with storeOffsetsWithPositions="true"
  - hl.q (string) can specify the query
  - hl.fl (string) specifies the field list.
  - hl.snippets (int) specifies how many underlying passages form the resulting snippet.
  - hl.tag.pre (string) specifies text which appears before a highlighted term.
  - hl.tag.post (string) specifies text which appears after a highlighted term.
  - hl.tag.ellipsis (string) specifies text which joins non-adjacent passages.
  - hl.defaultSummary (bool) specifies if a field should have a default summary.
  - hl.encoder (string) can be 'html' (html escapes content) or 'simple' (no escaping).
  - hl.score.k1 (float) specifies bm25 scoring parameter 'k1'
  - hl.score.b (float) specifies bm25 scoring parameter 'b'
  - hl.score.pivot (float) specifies bm25 scoring parameter 'avgdl'
  - hl.bs.type (string) specifies how to divide text into passages: [SENTENCE, LINE, WORD, CHAR, WHOLE]
  - hl.bs.language (string) specifies language code for BreakIterator. default is empty string (root locale)
  - hl.bs.country (string) specifies country code for BreakIterator. default is empty string (root locale)
  - hl.bs.variant (string) specifies country code for BreakIterator. default is empty string (root locale)
  - hl.maxAnalyzedChars specifies how many characters at most will be processed in a document.
  - hl.multiValuedSeparatorChar specifies the logical separator between values for multi-valued fields.
  - hl.highlightMultiTerm enables highlighting for range/wildcard/fuzzy/prefix queries. NOTE: currently hl.maxAnalyzedChars cannot yet be specified per-field
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `PostingsSolrHighlighter.SolrExtendedPostingsHighlighter` From `getHighlighter(org.apache.solr.request.SolrQueryRequest)`.

  - ### Field Summary

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

      `DEFAULT_PHRASE_LIMIT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PostingsSolrHighlighter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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 NamedList<Object>` | `encodeSnippets(String[] keys, String[] fieldNames, Map<String,String[]> snippets)` Encodes the resulting snippets into a namedlist
    `protected PostingsHighlighter` | `getHighlighter(SolrQueryRequest req)` Creates an instance of the Lucene PostingsHighlighter.
    `protected String[]` | `getUniqueKeys(SolrIndexSearcher searcher, int[] docIDs)` Retrieves the unique keys for the topdocs to key the results
    `void` | `init(PluginInfo info)`
    `protected BreakIterator` | `parseBreakIterator(String type, Locale locale)` parse a break iterator type for the specified locale
    `protected Locale` | `parseLocale(String language, String country, String variant)` parse a locale from a language+country+variant spec
    `protected int[]` | `toDocIDs(DocList docs)` Converts solr's DocList to the int[] docIDs

    - ### 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`

- - ### Constructor Detail

    - #### PostingsSolrHighlighter

          public PostingsSolrHighlighter()

  - ### Method Detail

    - #### init

          public void init(PluginInfo info)

      Specified by:
        `init` in interface `PluginInfoInitialized`

    - #### doHighlighting

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

      Description copied from class: `SolrHighlighter`
      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`

    - #### getHighlighter

          protected PostingsHighlighter getHighlighter(SolrQueryRequest req)

      Creates an instance of the Lucene PostingsHighlighter. Provided for subclass extension so that a subclass can return a subclass of `PostingsSolrHighlighter.SolrExtendedPostingsHighlighter`.

    - #### encodeSnippets

          protected NamedList<Object> encodeSnippets(String[] keys,
                                                     String[] fieldNames,
                                                     Map<String,String[]> snippets)

      Encodes the resulting snippets into a namedlist
      Parameters:
        `keys` - the document unique keys
        `fieldNames` - field names to highlight in the order
        `snippets` - map from field name to snippet array for the docs
      Returns:
        encoded namedlist of summaries

    - #### toDocIDs

          protected int[] toDocIDs(DocList docs)

      Converts solr's DocList to the int[] docIDs

    - #### getUniqueKeys

          protected String[] getUniqueKeys(SolrIndexSearcher searcher,
                                           int[] docIDs)
                                    throws IOException

      Retrieves the unique keys for the topdocs to key the results
      Throws:
        `IOException`

    - #### parseBreakIterator

          protected BreakIterator parseBreakIterator(String type,
                                                     Locale locale)

      parse a break iterator type for the specified locale

    - #### parseLocale

          protected Locale parseLocale(String language,
                                       String country,
                                       String variant)

      parse a locale from a language+country+variant spec

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