org.apache.solr.util
Class HighlightingUtils

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

public class HighlightingUtils
extends Object

Collection of Utility and Factory methods for Highlighting.


Constructor Summary
HighlightingUtils()
           
 
Method Summary
static NamedList doHighlighting(DocList docs, 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.
static Formatter getFormatter(String fieldName, SolrQueryRequest request)
          Return a formatter appropriate for this field.
static Fragmenter getFragmenter(String fieldName, SolrQueryRequest request)
          Return a fragmenter appropriate for this field.
static Highlighter getHighlighter(Query query, String fieldName, SolrQueryRequest request)
          Return a Highlighter appropriate for this field.
static String[] getHighlightFields(Query query, SolrQueryRequest request, String[] defaultFields)
          Return a String array of the fields to be highlighted.
static int getMaxSnippets(String fieldName, SolrQueryRequest request)
          Return the max number of snippets for this field.
static QueryScorer getQueryScorer(Query query, 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 Highlighter getHighlighter(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

getQueryScorer

public static QueryScorer getQueryScorer(Query query,
                                         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 String[] getHighlightFields(Query query,
                                          SolrQueryRequest request,
                                          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(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 Formatter getFormatter(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 Fragmenter getFragmenter(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,
                                       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.

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


Copyright © 2006 - 2009 The Apache Software Foundation