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
  • Field Details

  • Constructor Details

    • DefaultSolrHighlighter

      public DefaultSolrHighlighter(SolrCore solrCore)
  • Method Details

    • init

      public void init(PluginInfo info)
      Specified by:
      init in interface PluginInfoInitialized
    • 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 phrase Highlighter appropriate for this field.
      Parameters:
      query - The current Query
      fieldName - The name of the field
      request - The current SolrQueryRequest
      tokenStream - 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 a Highlighter appropriate for this field.
      Parameters:
      query - The current Query
      fieldName - The name of the field
      request - 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 a QueryScorer suitable for this Query and field.
      Parameters:
      query - The current query
      fieldName - The name of the field
      tokenStream - document text tokenStream that implements reset() efficiently (e.g. CachingTokenFilter). If it's used, call reset() first.
      request - The SolrQueryRequest
    • getQueryScorer

      protected org.apache.lucene.search.highlight.Scorer getQueryScorer(org.apache.lucene.search.Query query, String fieldName, SolrQueryRequest request)
      Return a Scorer suitable for this Query and field.
      Parameters:
      query - The current query
      fieldName - The name of the field
      request - 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 field
      params - 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 field
      params - The params controlling Highlighting
    • getFormatter

      protected org.apache.lucene.search.highlight.Formatter getFormatter(String fieldName, org.apache.solr.common.params.SolrParams params)
      Return a Formatter 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 field
      params - 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 an Encoder 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 field
      params - 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 a Fragmenter 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 field
      params - 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 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
    • 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, org.apache.lucene.index.TermVectors termVectors, 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 to SolrDocumentFetcher.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.TermVectors termVectors, 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 field NamedList. 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, org.apache.lucene.index.TermVectors termVectors, 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