Class UnifiedSolrHighlighter

  • All Implemented Interfaces:

    public class UnifiedSolrHighlighter
    extends SolrHighlighter
    implements PluginInfoInitialized
    Highlighter impl that uses UnifiedHighlighter

    Example configuration with default values:

     <requestHandler name="/select" class="solr.SearchHandler">
     <lst name="defaults">
     <str name="hl.method">unified</str>
     <int name="hl.snippets">1</int>
     <str name="hl.tag.pre">&lt;em&gt;</str>
     <str name="">&lt;/em&gt;</str>
     <str name="hl.simple.pre">&lt;em&gt;</str>
     <str name="">&lt;/em&gt;</str>
     <str name="hl.tag.ellipsis">(internal/unspecified)</str>
     <bool name="hl.defaultSummary">false</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=""></str>
     <str name=""></str>
     <str name=""></str>
     <str name="">SENTENCE</str>
     <int name="hl.maxAnalyzedChars">51200</int>
     <bool name="hl.highlightMultiTerm">true</bool>
     <bool name="hl.usePhraseHighlighter">true</bool>
     <int name="hl.cacheFieldValCharsThreshold">524288</int>
     <str name="hl.offsetSource"></str>
     <bool name="hl.weightMatches">true</bool>


    • hl.q (string) can specify the query
    • hl.fl (string) specifies the field list.
    • hl.snippets (int) specifies how many snippets to return.
    • hl.tag.pre (string) specifies text which appears before a highlighted term.
    • (string) specifies text which appears after a highlighted term.
    • hl.simple.pre (string) specifies text which appears before a highlighted term. (prefer hl.tag.pre)
    • (string) specifies text which appears before a highlighted term. (prefer
    • hl.tag.ellipsis (string) specifies text which joins non-adjacent passages. The default is to retain each value in a list without joining them.
    • hl.defaultSummary (bool) specifies if a field should have a default summary of the leading text.
    • 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'
    • (string) specifies how to divide text into passages: [SENTENCE, LINE, WORD, CHAR, WHOLE]
    • (string) specifies language code for BreakIterator. default is empty string (root locale)
    • (string) specifies country code for BreakIterator. default is empty string (root locale)
    • (string) specifies country code for BreakIterator. default is empty string (root locale)
    • hl.maxAnalyzedChars (int) specifies how many characters at most will be processed in a document for any one field.
    • hl.highlightMultiTerm (bool) enables highlighting for range/wildcard/fuzzy/prefix queries at some cost. default is true
    • hl.usePhraseHighlighter (bool) enables phrase highlighting. default is true
    • hl.cacheFieldValCharsThreshold (int) controls how many characters from a field are cached. default is 524288 (1MB in 2 byte chars)
    • hl.offsetSource (string) specifies which offset source to use, prefers postings, but will use what's available if not specified
    • hl.weightMatches (bool) enables Lucene Weight Matches mode
    WARNING: This API is experimental and might change in incompatible ways in the next release.
    • Constructor Detail

      • UnifiedSolrHighlighter

        public UnifiedSolrHighlighter()
    • Method Detail

      • doHighlighting

        public org.apache.solr.common.util.NamedList<Object> doHighlighting​(DocList docs,
                                                                            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
        docs - query results
        query - the query
        req - the current request
        defaultFields - default list of fields to summarize
        NamedList containing a NamedList for each document, which in turns contains sets (field, summary) pairs.
      • encodeSnippets

        protected org.apache.solr.common.util.NamedList<Object> encodeSnippets​(String[] keys,
                                                                               String[] fieldNames,
                                                                               Map<String,​String[]> snippets)
        Encodes the resulting snippets into a namedlist
        keys - the document unique keys
        fieldNames - field names to highlight in the order
        snippets - map from field name to snippet array for the docs
        encoded namedlist of summaries
      • toDocIDs

        protected int[] toDocIDs​(DocList docs)
        Converts solr's DocList to the int[] docIDs