Class UnifiedSolrHighlighter

  • All Implemented Interfaces:
    PluginInfoInitialized
    Direct Known Subclasses:
    PostingsSolrHighlighter

    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="hl.tag.post">&lt;/em&gt;</str>
     <str name="hl.simple.pre">&lt;em&gt;</str>
     <str name="hl.simple.post">&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="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">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>
     </lst>
     </requestHandler>
     

    Notes:

    • 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.
    • hl.tag.post (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)
    • hl.simple.post (string) specifies text which appears before a highlighted term. (prefer hl.tag.post)
    • 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'
    • 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 (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 NamedList<Object> doHighlighting​(DocList docs,
                                                org.apache.lucene.search.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
      • 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