org.apache.solr.util
Class HighlightingUtils

java.lang.Object
  extended by org.apache.solr.util.HighlightingUtils

public class HighlightingUtils
extends java.lang.Object

Collection of Utility and Factory methods for Highlighting.


Constructor Summary
HighlightingUtils()
           
 
Method Summary
static NamedList doHighlighting(DocList docs, org.apache.lucene.search.Query query, SolrQueryRequest req, java.lang.String[] defaultFields)
          Generates a list of Highlighted query fragments for each item in a list of documents, or returns null if highlighting is disabled.
static org.apache.lucene.search.highlight.Formatter getFormatter(java.lang.String fieldName, SolrQueryRequest request)
          Return a formatter appropriate for this field.
static org.apache.lucene.search.highlight.Fragmenter getFragmenter(java.lang.String fieldName, SolrQueryRequest request)
          Return a fragmenter appropriate for this field.
static org.apache.lucene.search.highlight.Highlighter getHighlighter(org.apache.lucene.search.Query query, java.lang.String fieldName, SolrQueryRequest request)
          Return a Highlighter appropriate for this field.
static java.lang.String[] getHighlightFields(org.apache.lucene.search.Query query, SolrQueryRequest request, java.lang.String[] defaultFields)
          Return a String array of the fields to be highlighted.
static int getMaxSnippets(java.lang.String fieldName, SolrQueryRequest request)
          Return the max number of snippets for this field.
static org.apache.lucene.search.highlight.QueryScorer getQueryScorer(org.apache.lucene.search.Query query, java.lang.String fieldName, SolrQueryRequest request)
          Return a QueryScorer suitable for this Query and field.
static boolean isHighlightingEnabled(SolrQueryRequest request)
          Check whether Highlighting is enabled for this request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HighlightingUtils

public HighlightingUtils()
Method Detail

isHighlightingEnabled

public static boolean isHighlightingEnabled(SolrQueryRequest request)
Check whether Highlighting is enabled for this request.

Parameters:
request - The current SolrQueryRequest
Returns:
true if highlighting enabled, false if not.

getHighlighter

public static org.apache.lucene.search.highlight.Highlighter getHighlighter(org.apache.lucene.search.Query query,
                                                                            java.lang.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

getQueryScorer

public static org.apache.lucene.search.highlight.QueryScorer getQueryScorer(org.apache.lucene.search.Query query,
                                                                            java.lang.String fieldName,
                                                                            SolrQueryRequest request)
Return a QueryScorer suitable for this Query and field.

Parameters:
query - The current query
fieldName - The name of the field
request - The SolrQueryRequest

getHighlightFields

public static java.lang.String[] getHighlightFields(org.apache.lucene.search.Query query,
                                                    SolrQueryRequest request,
                                                    java.lang.String[] defaultFields)
Return a String array of the fields to be highlighted. Falls back to the programatic defaults, or the default search field if the list of fields is not specified in either the handler configuration or the request.

Parameters:
query - The current Query
request - The current SolrQueryRequest
defaultFields - Programmatic default highlight fields, used if nothing is specified in the handler config or the request.

getMaxSnippets

public static int getMaxSnippets(java.lang.String fieldName,
                                 SolrQueryRequest request)
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
request - The current SolrQueryRequest

getFormatter

public static org.apache.lucene.search.highlight.Formatter getFormatter(java.lang.String fieldName,
                                                                        SolrQueryRequest request)
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
request - The current SolrQueryRequest
Returns:
An appropriate Formatter.

getFragmenter

public static org.apache.lucene.search.highlight.Fragmenter getFragmenter(java.lang.String fieldName,
                                                                          SolrQueryRequest request)
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
request - The current SolrQueryRequest
Returns:
An appropriate Fragmenter.

doHighlighting

public static NamedList doHighlighting(DocList docs,
                                       org.apache.lucene.search.Query query,
                                       SolrQueryRequest req,
                                       java.lang.String[] defaultFields)
                                throws java.io.IOException
Generates a list of Highlighted query fragments for each item in a list of documents, or returns null if highlighting is disabled.

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:
java.io.IOException


Copyright © 2006 - 2008 The Apache Software Foundation