Package 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 Description static class
DefaultSolrHighlighter.FvhContainer
-
Field Summary
Fields Modifier and Type Field 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_MAX_CHARS, DEFAULT_PHRASE_LIMIT
-
-
Constructor Summary
Constructors Constructor Description DefaultSolrHighlighter(SolrCore solrCore)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
alternateField(org.apache.solr.common.SolrDocument doc, int docId, String fieldName, DefaultSolrHighlighter.FvhContainer fvhContainer, org.apache.lucene.search.Query query, org.apache.lucene.index.IndexReader reader, SolrQueryRequest req)
Returns the alternate highlight object for this field -- a String[] by default.protected org.apache.lucene.analysis.TokenStream
createAnalyzerTStream(SchemaField schemaField, String docText)
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 Object
doHighlightingByFastVectorHighlighter(org.apache.solr.common.SolrDocument doc, int docId, SchemaField schemaField, DefaultSolrHighlighter.FvhContainer fvhContainer, org.apache.lucene.index.IndexReader reader, SolrQueryRequest req)
Highlights and returns the highlight object for this field -- a String[] by default.protected Object
doHighlightingByHighlighter(org.apache.solr.common.SolrDocument doc, int docId, SchemaField schemaField, org.apache.lucene.search.Query query, org.apache.lucene.index.IndexReader reader, SolrQueryRequest req)
Highlights and returns the highlight object for this field -- a String[] by default.protected Object
doHighlightingOfField(org.apache.solr.common.SolrDocument doc, int docId, SchemaField schemaField, DefaultSolrHighlighter.FvhContainer fvhContainer, org.apache.lucene.search.Query query, org.apache.lucene.index.IndexReader reader, SolrQueryRequest req, org.apache.solr.common.params.SolrParams params)
protected org.apache.lucene.search.vectorhighlight.BoundaryScanner
getBoundaryScanner(String fieldName, org.apache.solr.common.params.SolrParams params)
protected Set<String>
getDocPrefetchFieldNames(String[] hlFieldNames, SolrQueryRequest req)
Returns the field names to be passed toSolrDocumentFetcher.solrDoc(int, SolrReturnFields)
.protected org.apache.lucene.search.highlight.Encoder
getEncoder(String fieldName, org.apache.solr.common.params.SolrParams params)
Return anEncoder
appropriate for this field.protected List<String>
getFieldValues(org.apache.solr.common.SolrDocument doc, String fieldName, int maxValues, int maxCharsToAnalyze, SolrQueryRequest req)
Fetches field values to highlight.protected org.apache.lucene.search.highlight.Formatter
getFormatter(String fieldName, org.apache.solr.common.params.SolrParams params)
Return aFormatter
appropriate for this field.protected org.apache.lucene.search.vectorhighlight.FragListBuilder
getFragListBuilder(String fieldName, org.apache.solr.common.params.SolrParams params)
protected org.apache.lucene.search.highlight.Fragmenter
getFragmenter(String fieldName, org.apache.solr.common.params.SolrParams params)
Return aFragmenter
appropriate for this field.protected org.apache.lucene.search.vectorhighlight.FragmentsBuilder
getFragmentsBuilder(String fieldName, org.apache.solr.common.params.SolrParams params)
protected org.apache.lucene.search.highlight.Highlighter
getHighlighter(org.apache.lucene.search.Query query, String fieldName, SolrQueryRequest request)
Return aHighlighter
appropriate for this field.protected int
getMaxSnippets(String fieldName, org.apache.solr.common.params.SolrParams params)
Return the max number of snippets for this field.protected org.apache.lucene.search.highlight.Highlighter
getPhraseHighlighter(org.apache.lucene.search.Query query, String fieldName, SolrQueryRequest request, org.apache.lucene.analysis.TokenStream tokenStream)
Return a phraseHighlighter
appropriate for this field.protected org.apache.lucene.search.highlight.Scorer
getQueryScorer(org.apache.lucene.search.Query query, String fieldName, SolrQueryRequest request)
Return aScorer
suitable for this Query and field.protected Object
getResponseForFragments(List<org.apache.lucene.search.highlight.TextFragment> frags, SolrQueryRequest req)
Given the fragments, return the result to be put in the fieldNamedList
.protected SolrFragmentsBuilder
getSolrFragmentsBuilder(String fieldName, org.apache.solr.common.params.SolrParams params)
protected org.apache.lucene.search.highlight.QueryScorer
getSpanQueryScorer(org.apache.lucene.search.Query query, String fieldName, org.apache.lucene.analysis.TokenStream tokenStream, SolrQueryRequest request)
Return aQueryScorer
suitable for this Query and field.void
init(PluginInfo info)
protected boolean
isMergeContiguousFragments(String fieldName, org.apache.solr.common.params.SolrParams params)
Return whether adjacent fragments should be merged.protected boolean
useFastVectorHighlighter(org.apache.solr.common.params.SolrParams params, SchemaField schemaField)
Determines if we should use the FastVectorHighlighter for this field.-
Methods inherited from class org.apache.solr.highlight.SolrHighlighter
emptyArray, expandWildcardsInFields, getHighlightFields, isHighlightingEnabled
-
-
-
-
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 interfacePluginInfoInitialized
-
getPhraseHighlighter
protected org.apache.lucene.search.highlight.Highlighter getPhraseHighlighter(org.apache.lucene.search.Query query, String fieldName, SolrQueryRequest request, org.apache.lucene.analysis.TokenStream tokenStream) throws IOException
Return a phraseHighlighter
appropriate for this field.- Parameters:
query
- The current QueryfieldName
- The name of the fieldrequest
- The current SolrQueryRequesttokenStream
- 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 org.apache.lucene.search.highlight.Highlighter getHighlighter(org.apache.lucene.search.Query query, String fieldName, SolrQueryRequest request)
Return aHighlighter
appropriate for this field.- Parameters:
query
- The current QueryfieldName
- The name of the fieldrequest
- The current SolrQueryRequest
-
getSpanQueryScorer
protected org.apache.lucene.search.highlight.QueryScorer getSpanQueryScorer(org.apache.lucene.search.Query query, String fieldName, org.apache.lucene.analysis.TokenStream tokenStream, SolrQueryRequest request)
Return aQueryScorer
suitable for this Query and field.- Parameters:
query
- The current querytokenStream
- document text tokenStream that implements reset() efficiently (e.g. CachingTokenFilter). If it's used, call reset() first.fieldName
- The name of the fieldrequest
- The SolrQueryRequest
-
getQueryScorer
protected org.apache.lucene.search.highlight.Scorer getQueryScorer(org.apache.lucene.search.Query query, String fieldName, SolrQueryRequest request)
Return aScorer
suitable for this Query and field.- Parameters:
query
- The current queryfieldName
- The name of the fieldrequest
- The SolrQueryRequest
-
getMaxSnippets
protected int getMaxSnippets(String fieldName, org.apache.solr.common.params.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 fieldparams
- The params controlling Highlighting
-
isMergeContiguousFragments
protected boolean isMergeContiguousFragments(String fieldName, org.apache.solr.common.params.SolrParams params)
Return whether adjacent fragments should be merged.- Parameters:
fieldName
- The name of the fieldparams
- The params controlling Highlighting
-
getFormatter
protected org.apache.lucene.search.highlight.Formatter getFormatter(String fieldName, org.apache.solr.common.params.SolrParams params)
Return aFormatter
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 fieldparams
- The params controlling Highlighting- Returns:
- An appropriate
Formatter
.
-
getEncoder
protected org.apache.lucene.search.highlight.Encoder getEncoder(String fieldName, org.apache.solr.common.params.SolrParams params)
Return anEncoder
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 fieldparams
- The params controlling Highlighting- Returns:
- An appropriate
Encoder
.
-
getFragmenter
protected org.apache.lucene.search.highlight.Fragmenter getFragmenter(String fieldName, org.apache.solr.common.params.SolrParams params)
Return aFragmenter
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 fieldparams
- The params controlling Highlighting- Returns:
- An appropriate
Fragmenter
.
-
getFragListBuilder
protected org.apache.lucene.search.vectorhighlight.FragListBuilder getFragListBuilder(String fieldName, org.apache.solr.common.params.SolrParams params)
-
getFragmentsBuilder
protected org.apache.lucene.search.vectorhighlight.FragmentsBuilder getFragmentsBuilder(String fieldName, org.apache.solr.common.params.SolrParams params)
-
getSolrFragmentsBuilder
protected SolrFragmentsBuilder getSolrFragmentsBuilder(String fieldName, org.apache.solr.common.params.SolrParams params)
-
getBoundaryScanner
protected org.apache.lucene.search.vectorhighlight.BoundaryScanner getBoundaryScanner(String fieldName, org.apache.solr.common.params.SolrParams params)
-
doHighlighting
public org.apache.solr.common.util.NamedList<Object> doHighlighting(DocList docs, org.apache.lucene.search.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 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
-
doHighlightingOfField
protected Object doHighlightingOfField(org.apache.solr.common.SolrDocument doc, int docId, SchemaField schemaField, DefaultSolrHighlighter.FvhContainer fvhContainer, org.apache.lucene.search.Query query, org.apache.lucene.index.IndexReader reader, SolrQueryRequest req, org.apache.solr.common.params.SolrParams params) throws IOException
- Throws:
IOException
-
getDocPrefetchFieldNames
protected Set<String> getDocPrefetchFieldNames(String[] hlFieldNames, SolrQueryRequest req)
Returns the field names to be passed toSolrDocumentFetcher.solrDoc(int, SolrReturnFields)
. 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(org.apache.solr.common.params.SolrParams params, SchemaField schemaField)
Determines if we should use the FastVectorHighlighter for this field.
-
doHighlightingByFastVectorHighlighter
protected Object doHighlightingByFastVectorHighlighter(org.apache.solr.common.SolrDocument doc, int docId, SchemaField schemaField, DefaultSolrHighlighter.FvhContainer fvhContainer, org.apache.lucene.index.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(org.apache.solr.common.SolrDocument doc, int docId, SchemaField schemaField, org.apache.lucene.search.Query query, org.apache.lucene.index.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(org.apache.solr.common.SolrDocument 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<org.apache.lucene.search.highlight.TextFragment> frags, SolrQueryRequest req)
Given the fragments, return the result to be put in the fieldNamedList
. This is an extension point to allow adding other metadata like the absolute offsets or scores.
-
alternateField
protected Object alternateField(org.apache.solr.common.SolrDocument doc, int docId, String fieldName, DefaultSolrHighlighter.FvhContainer fvhContainer, org.apache.lucene.search.Query query, org.apache.lucene.index.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 org.apache.lucene.analysis.TokenStream createAnalyzerTStream(SchemaField schemaField, String docText) throws IOException
- Throws:
IOException
-
-