Class DefaultSolrHighlighter

    • Constructor Detail

      • DefaultSolrHighlighter

        public DefaultSolrHighlighter​(SolrCore solrCore)
    • Method Detail

      • 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
        tokenStream - document text tokenStream that implements reset() efficiently (e.g. CachingTokenFilter). If it's used, call reset() first.
        fieldName - The name of the field
        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,
                                     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,
                                                     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,
                                                                            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,
                                                                        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,
                                                                              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,
                                                                                              SolrParams params)
      • getFragmentsBuilder

        protected org.apache.lucene.search.vectorhighlight.FragmentsBuilder getFragmentsBuilder​(String fieldName,
                                                                                                SolrParams params)
      • getBoundaryScanner

        protected org.apache.lucene.search.vectorhighlight.BoundaryScanner getBoundaryScanner​(String fieldName,
                                                                                              SolrParams params)
      • doHighlighting

        public 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
      • getDocPrefetchFieldNames

        protected Set<String> getDocPrefetchFieldNames​(String[] hlFieldNames,
                                                       SolrQueryRequest req)
        Returns the field names to be passed to SolrIndexSearcher.doc(int, Set). 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​(SolrParams params,
                                                   SchemaField schemaField)
        Determines if we should use the FastVectorHighlighter for this field.
      • doHighlightingByHighlighter

        protected Object doHighlightingByHighlighter​(org.apache.lucene.document.Document 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.lucene.document.Document 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.