Package org.apache.solr.highlight
Class UnifiedSolrHighlighter
- java.lang.Object
-
- org.apache.solr.highlight.SolrHighlighter
-
- org.apache.solr.highlight.UnifiedSolrHighlighter
-
- All Implemented Interfaces:
PluginInfoInitialized
public class UnifiedSolrHighlighter extends SolrHighlighter implements PluginInfoInitialized
Highlighter impl that usesUnifiedHighlighter
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"><em></str> <str name="hl.tag.post"></em></str> <str name="hl.simple.pre"><em></str> <str name="hl.simple.post"></em></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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
UnifiedSolrHighlighter.SolrExtendedUnifiedHighlighter
-
Field Summary
Fields Modifier and Type Field Description protected static String
SNIPPET_SEPARATOR
-
Fields inherited from class org.apache.solr.highlight.SolrHighlighter
DEFAULT_MAX_CHARS, DEFAULT_PHRASE_LIMIT
-
-
Constructor Summary
Constructors Constructor Description UnifiedSolrHighlighter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.solr.common.util.NamedList<Object>
doHighlighting(DocList docs, org.apache.lucene.search.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 org.apache.solr.common.util.NamedList<Object>
encodeSnippets(String[] keys, String[] fieldNames, Map<String,String[]> snippets)
Encodes the resulting snippets into a namedlistprotected org.apache.lucene.search.uhighlight.UnifiedHighlighter
getHighlighter(SolrQueryRequest req)
Creates an instance of the LuceneUnifiedHighlighter
.protected String[]
getUniqueKeys(SolrIndexSearcher searcher, int[] docIDs)
Retrieves the unique keys for the topdocs to key the resultsvoid
init(PluginInfo info)
protected int[]
toDocIDs(DocList docs)
Converts solr's DocList to the int[] docIDs-
Methods inherited from class org.apache.solr.highlight.SolrHighlighter
emptyArray, expandWildcardsInFields, getHighlightFields, isHighlightingEnabled
-
-
-
-
Field Detail
-
SNIPPET_SEPARATOR
protected static final String SNIPPET_SEPARATOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(PluginInfo info)
- Specified by:
init
in interfacePluginInfoInitialized
-
doHighlighting
public org.apache.solr.common.util.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 classSolrHighlighter
- Parameters:
docs
- query resultsquery
- the queryreq
- the current requestdefaultFields
- 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 org.apache.lucene.search.uhighlight.UnifiedHighlighter getHighlighter(SolrQueryRequest req)
Creates an instance of the LuceneUnifiedHighlighter
. Provided for subclass extension so that a subclass can return a subclass ofUnifiedSolrHighlighter.SolrExtendedUnifiedHighlighter
.
-
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- Parameters:
keys
- the document unique keysfieldNames
- field names to highlight in the ordersnippets
- 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
-
-