SolrPluginUtils (Solr 3.6.2 API)
Keywords: org.apache.solr.util.SolrPluginUtils class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.solr.util
Class SolrPluginUtils

    java.lang.Object
      org.apache.solr.util.SolrPluginUtils

    public class SolrPluginUtils

extends Object

Utilities that may be of use to RequestHandlers.

Many of these functions have code that was stolen/mutated from StandardRequestHandler.

:TODO: refactor StandardRequestHandler to use these utilities

:TODO: Many "standard" functionality methods are not cognisant of default parameter settings.

Nested Class Summary
`static class` | `SolrPluginUtils.DisjunctionMaxQueryParser` A subclass of SolrQueryParser that supports aliasing fields for constructing DisjunctionMaxQueries.
`static class` | `SolrPluginUtils.IdentityRegenerator` A CacheRegenerator that can be used whenever the items in the cache are not dependant on the current searcher.

Field Summary
`static String` | `FL` Deprecated. Use org.apache.solr.common.params.CommonParams.FL.

Constructor Summary
`SolrPluginUtils()`

Method Summary
`static void` | `addOrReplaceResults(SolrQueryResponse rsp, SolrDocumentList docs)` Given a SolrQueryResponse replace the DocList if it is in the result.
`static SolrDocumentList` | `docListToSolrDocumentList(DocList docs, SolrIndexSearcher searcher, Set<String> fields, Map<SolrDocument,Integer> ids)` Convert a DocList to a SolrDocumentList The optional param "ids" is populated with the lucene document id for each SolrDocument.
`static DocList` | `doSimpleQuery(String sreq, SolrQueryRequest req, int start, int limit)` Executes a basic query in lucene syntax
`static NamedList` | `doStandardDebug(SolrQueryRequest req, String userQuery, Query query, DocList results)` Returns a NamedList containing many "standard" pieces of debugging information.
`static NamedList` | `doStandardDebug(SolrQueryRequest req, String userQuery, Query query, DocList results, CommonParams params)` Deprecated. Use doStandardDebug(SolrQueryRequest,String,Query,DocList) with setDefaults
`static NamedList<NamedList<Object>>` | `explanationsToNamedLists(NamedList<Explanation> explanations)`
`static NamedList<Object>` | `explanationToNamedList(Explanation e)`
`static void` | `flattenBooleanQuery(BooleanQuery to, BooleanQuery from)` Recursively walks the "from" query pulling out sub-queries and adding them to the "to" query.
`static boolean` | `getBooleanParam(SolrQueryRequest req, String param, boolean def)` Deprecated. use SolrParam.getBool(String,boolean)
`static NamedList` | `getExplainList(Query query, DocList docs, SolrIndexSearcher searcher, IndexSchema schema)` Deprecated. this returns the explanations as Strings, instead it is recommeded to use getExplanations and call toString() yourself, or use explanationsToNamedLists
`static NamedList<Explanation>` | `getExplanations(Query query, DocList docs, SolrIndexSearcher searcher, IndexSchema schema)` Generates an NamedList of Explanations for each item in a list of docs.
`static Number` | `getNumberParam(SolrQueryRequest req, String param, Number def)` Deprecated. use SolrParam.getFloat(String,float)
`static String` | `getParam(SolrQueryRequest req, String param, String def)` Deprecated. use SolrParam.get(String,String)
`static Sort` | `getSort(SolrQueryRequest req)` Determines the correct Sort based on the request parameter "sort"
`static void` | `invokeSetters(Object bean, NamedList initArgs)`
`static int` | `numDocs(SolrIndexSearcher s, Query q, Query f)` SolrIndexSearch.numDocs(Query,Query) freaks out if the filtering query is null, so we use this workarround.
`static void` | `optimizePreFetchDocs(DocList docs, Query query, SolrQueryRequest req, SolrQueryResponse res)` Pre-fetch documents into the index searcher's document cache.
`static Map<String,Float>` | `parseFieldBoosts(String in)` Given a string containing fieldNames and boost info, converts it to a Map from field name to boost info.
`static Map<String,Float>` | `parseFieldBoosts(String[] fieldLists)` Like `parseFieldBoosts(String)`, but parses all the strings in the provided array (which may be null).
`static List<Query>` | `parseFilterQueries(SolrQueryRequest req)` Builds a list of Query objects that should be used to filter results
`static List<Query>` | `parseFuncs(IndexSchema s, String in)` Deprecated.
`static List<Query>` | `parseQueryStrings(SolrQueryRequest req, String[] queries)` Turns an array of query strings into a List of Query objects.
`static CharSequence` | `partialEscape(CharSequence s)` Escapes all special characters except '"', '-', and '+'
`static String` | `resolveUpdateChainParam(SolrParams params, org.slf4j.Logger log)` Deprecated.
`static void` | `setDefaults(SolrQueryRequest req, SolrParams defaults)` Set defaults on a SolrQueryRequest.
`static void` | `setDefaults(SolrQueryRequest req, SolrParams defaults, SolrParams appends, SolrParams invariants)` Set default-ish params on a SolrQueryRequest.
`static void` | `setMinShouldMatch(BooleanQuery q, String spec)` Checks the number of optional clauses in the query, and compares it with the specification string to determine the proper value to use.
`static int` | `setReturnFields(SolrQueryRequest req, SolrQueryResponse res)` Assumes the standard query param of "fl" to specify the return fields
`static int` | `setReturnFields(String fl, SolrQueryResponse res)` Given a space seperated list of field names, sets the field list on the SolrQueryResponse.
`static String[]` | `split(String value)` Split a value that may contain a comma, space of bar separated list.
`static CharSequence` | `stripIllegalOperators(CharSequence s)` Strips operators that are used illegally, otherwise reuturns it's input.
`static CharSequence` | `stripUnbalancedQuotes(CharSequence s)` Returns it's input if there is an even (ie: balanced) number of '"' characters -- otherwise returns a String in which all '"' characters are striped out.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### FL

    @Deprecated
    public static String FL

  Deprecated. Use org.apache.solr.common.params.CommonParams.FL.
  standard param for field list

Constructor Detail

### SolrPluginUtils

    public SolrPluginUtils()

Method Detail

### setDefaults

    public static void setDefaults(SolrQueryRequest req,
                                   SolrParams defaults)

  Set defaults on a SolrQueryRequest. RequestHandlers can use this method to ensure their defaults are visible to other components such as the response writer

### setDefaults

    public static void setDefaults(SolrQueryRequest req,
                                   SolrParams defaults,
                                   SolrParams appends,
                                   SolrParams invariants)

  Set default-ish params on a SolrQueryRequest. RequestHandlers can use this method to ensure their defaults and overrides are visible to other components such as the response writer

  Parameters:
    `req` - The request whose params we are interested i
    `defaults` - values to be used if no values are specified in the request params
    `appends` - values to be appended to those from the request (or defaults) when dealing with multi-val params, or treated as another layer of defaults for singl-val params.
    `invariants` - values which will be used instead of any request, or default values, regardless of context.

### numDocs

    public static int numDocs(SolrIndexSearcher s,
                              Query q,
                              Query f)
                       throws IOException

  SolrIndexSearch.numDocs(Query,Query) freaks out if the filtering query is null, so we use this workarround.

  Throws:
    `IOException`

### getParam

    @Deprecated
    public static String getParam(SolrQueryRequest req,
                                             String param,
                                             String def)

  Deprecated. use SolrParam.get(String,String)

  Returns the param, or the default if it's empty or not specified.

### getNumberParam

    @Deprecated
    public static Number getNumberParam(SolrQueryRequest req,
                                                   String param,
                                                   Number def)

  Deprecated. use SolrParam.getFloat(String,float)

  Treats the param value as a Number, returns the default if nothing is there or if it's not a number.

### getBooleanParam

    @Deprecated
    public static boolean getBooleanParam(SolrQueryRequest req,
                                                     String param,
                                                     boolean def)

  Deprecated. use SolrParam.getBool(String,boolean)

  Treats parameter value as a boolean. The string 'false' is false; any other non-empty string is true.

### split

    public static String[] split(String value)

  Split a value that may contain a comma, space of bar separated list.

### setReturnFields

    public static int setReturnFields(SolrQueryRequest req,
                                      SolrQueryResponse res)

  Assumes the standard query param of "fl" to specify the return fields

  See Also:
    `setReturnFields(String,SolrQueryResponse)`

### setReturnFields

    public static int setReturnFields(String fl,
                                      SolrQueryResponse res)

  Given a space seperated list of field names, sets the field list on the SolrQueryResponse.

  Returns:
    bitfield of SolrIndexSearcher flags that need to be set

### optimizePreFetchDocs

    public static void optimizePreFetchDocs(DocList docs,
                                            Query query,
                                            SolrQueryRequest req,
                                            SolrQueryResponse res)
                                     throws IOException

  Pre-fetch documents into the index searcher's document cache. This is an entirely optional step which you might want to perform for the following reasons:
  - Locates the document-retrieval costs in one spot, which helps detailed performance measurement
  - Determines a priori what fields will be needed to be fetched by various subtasks, like response writing and highlighting. This minimizes the chance that many needed fields will be loaded lazily. (it is more efficient to load all the field we require normally).
  If lazy field loading is disabled, this method does nothing.

  Throws:
    `IOException`

### doStandardDebug

    @Deprecated
    public static NamedList doStandardDebug(SolrQueryRequest req,
                                                       String userQuery,
                                                       Query query,
                                                       DocList results,
                                                       CommonParams params)
                                     throws IOException

  Deprecated. Use doStandardDebug(SolrQueryRequest,String,Query,DocList) with setDefaults

  Returns a NamedList containing many "standard" pieces of debugging information.

  - rawquerystring - the 'q' param exactly as specified by the client
  - querystring - the 'q' param after any preprocessing done by the plugin
  - parsedquery - the main query executed formated by the Solr QueryParsing utils class (which knows about field types)
  - parsedquery_toString - the main query executed formated by it's own toString method (in case it has internal state Solr doesn't know about)
  - expain - the list of score explanations for each document in results against query.
  - otherQuery - the query string specified in 'explainOther' query param.
  - explainOther - the list of score explanations for each document in results against 'otherQuery'

  Parameters:
    `req` - the request we are dealing with
    `userQuery` - the users query as a string, after any basic preprocessing has been done
    `query` - the query built from the userQuery (and perhaps other clauses) that identifies the main result set of the response.
    `results` - the main result set of the response
  Throws:
    `IOException`

### doStandardDebug

    public static NamedList doStandardDebug(SolrQueryRequest req,
                                            String userQuery,
                                            Query query,
                                            DocList results)
                                     throws IOException

  Returns a NamedList containing many "standard" pieces of debugging information.

  - rawquerystring - the 'q' param exactly as specified by the client
  - querystring - the 'q' param after any preprocessing done by the plugin
  - parsedquery - the main query executed formated by the Solr QueryParsing utils class (which knows about field types)
  - parsedquery_toString - the main query executed formated by it's own toString method (in case it has internal state Solr doesn't know about)
  - explain - the list of score explanations for each document in results against query.
  - otherQuery - the query string specified in 'explainOther' query param.
  - explainOther - the list of score explanations for each document in results against 'otherQuery'

  Parameters:
    `req` - the request we are dealing with
    `userQuery` - the users query as a string, after any basic preprocessing has been done
    `query` - the query built from the userQuery (and perhaps other clauses) that identifies the main result set of the response.
    `results` - the main result set of the response
  Throws:
    `IOException`

### explanationToNamedList

    public static NamedList<Object> explanationToNamedList(Explanation e)

### explanationsToNamedLists

    public static NamedList<NamedList<Object>> explanationsToNamedLists(NamedList<Explanation> explanations)

### getExplanations

    public static NamedList<Explanation> getExplanations(Query query,
                                                         DocList docs,
                                                         SolrIndexSearcher searcher,
                                                         IndexSchema schema)
                                                  throws IOException

  Generates an NamedList of Explanations for each item in a list of docs.

  Parameters:
    `query` - The Query you want explanations in the context of
    `docs` - The Documents you want explained relative that query
  Throws:
    `IOException`

### getExplainList

    @Deprecated
    public static NamedList getExplainList(Query query,
                                                      DocList docs,
                                                      SolrIndexSearcher searcher,
                                                      IndexSchema schema)
                                    throws IOException

  Deprecated. this returns the explanations as Strings, instead it is recommeded to use getExplanations and call toString() yourself, or use explanationsToNamedLists

  Executes a basic query Generates an list of Explanations for each item in a list of docs.

  Parameters:
    `query` - The Query you want explanations in the context of
    `docs` - The Documents you want explained relative that query
  Throws:
    `IOException`

### doSimpleQuery

    public static DocList doSimpleQuery(String sreq,
                                        SolrQueryRequest req,
                                        int start,
                                        int limit)
                                 throws IOException

  Executes a basic query in lucene syntax

  Throws:
    `IOException`

### parseFieldBoosts

    public static Map<String,Float> parseFieldBoosts(String in)

  Given a string containing fieldNames and boost info, converts it to a Map from field name to boost info.

  Doesn't care if boost info is negative, you're on your own.

  Doesn't care if boost info is missing, again: you're on your own.

  Parameters:
    `in` - a String like "fieldOne^2.3 fieldTwo fieldThree^-0.4"
  Returns:
    Map of fieldOne => 2.3, fieldTwo => null, fieldThree => -0.4

### parseFieldBoosts

    public static Map<String,Float> parseFieldBoosts(String[] fieldLists)

  Like `parseFieldBoosts(String)`, but parses all the strings in the provided array (which may be null).

  Parameters:
    `fieldLists` - an array of Strings eg. `{"fieldOne^2.3", "fieldTwo", fieldThree^-0.4}`
  Returns:
    Map of fieldOne => 2.3, fieldTwo => null, fieldThree => -0.4

### parseFuncs

    @Deprecated
    public static List<Query> parseFuncs(IndexSchema s,
                                                    String in)
                                  throws ParseException

  Deprecated.

  Given a string containing functions with optional boosts, returns an array of Queries representing those functions with the specified boosts.

  NOTE: intra-function whitespace is not allowed.

  Throws:
    `ParseException`
  See Also:
    `parseFieldBoosts(java.lang.String)`

### setMinShouldMatch

    public static void setMinShouldMatch(BooleanQuery q,
                                         String spec)

  Checks the number of optional clauses in the query, and compares it with the specification string to determine the proper value to use.

  Details about the specification format can be found here

  A few important notes...

  - If the calculations based on the specification determine that no optional clauses are needed, BooleanQuerysetMinMumberShouldMatch will never be called, but the usual rules about BooleanQueries still apply at search time (a BooleanQuery containing no required clauses must still match at least one optional clause)
  - No matter what number the calculation arrives at, BooleanQuery.setMinShouldMatch() will never be called with a value greater then the number of optional clauses (or less then 1)

  :TODO: should optimize the case where number is same as clauses to just make them all "required"

### flattenBooleanQuery

    public static void flattenBooleanQuery(BooleanQuery to,
                                           BooleanQuery from)

  Recursively walks the "from" query pulling out sub-queries and adding them to the "to" query.

  Boosts are multiplied as needed. Sub-BooleanQueryies which are not optional will not be flattened. From will be mangled durring the walk, so do not attempt to reuse it.

### partialEscape

    public static CharSequence partialEscape(CharSequence s)

  Escapes all special characters except '"', '-', and '+'

  See Also:
    `QueryParser.escape(java.lang.String)`

### stripIllegalOperators

    public static CharSequence stripIllegalOperators(CharSequence s)

  Strips operators that are used illegally, otherwise reuturns it's input. Some examples of illegal user queries are: "chocolate +- chip", "chocolate - - chip", and "chocolate chip -".

### stripUnbalancedQuotes

    public static CharSequence stripUnbalancedQuotes(CharSequence s)

  Returns it's input if there is an even (ie: balanced) number of '"' characters -- otherwise returns a String in which all '"' characters are striped out.

### getSort

    public static Sort getSort(SolrQueryRequest req)

  Determines the correct Sort based on the request parameter "sort"

  Returns:
    null if no sort is specified.

### parseFilterQueries

    public static List<Query> parseFilterQueries(SolrQueryRequest req)
                                          throws ParseException

  Builds a list of Query objects that should be used to filter results

  Returns:
    null if no filter queries
  Throws:
    `ParseException`
  See Also:
    `CommonParams.FQ`

### parseQueryStrings

    public static List<Query> parseQueryStrings(SolrQueryRequest req,
                                                String[] queries)
                                         throws ParseException

  Turns an array of query strings into a List of Query objects.

  Returns:
    null if no queries are generated
  Throws:
    `ParseException`

### docListToSolrDocumentList

    public static SolrDocumentList docListToSolrDocumentList(DocList docs,
                                                             SolrIndexSearcher searcher,
                                                             Set<String> fields,
                                                             Map<SolrDocument,Integer> ids)
                                                      throws IOException

  Convert a DocList to a SolrDocumentList The optional param "ids" is populated with the lucene document id for each SolrDocument.

  Parameters:
    `docs` - The `DocList` to convert
    `searcher` - The `SolrIndexSearcher` to use to load the docs from the Lucene index
    `fields` - The names of the Fields to load
    `ids` - A map to store the ids of the docs
  Returns:
    The new `SolrDocumentList` containing all the loaded docs
  Throws:
    `IOException` - if there was a problem loading the docs
  Since:
    solr 1.4

### addOrReplaceResults

    public static void addOrReplaceResults(SolrQueryResponse rsp,
                                           SolrDocumentList docs)

  Given a SolrQueryResponse replace the DocList if it is in the result. Otherwise add it to the response

  Since:
    solr 1.4

### invokeSetters

    public static void invokeSetters(Object bean,
                                     NamedList initArgs)

### resolveUpdateChainParam

    public static String resolveUpdateChainParam(SolrParams params,
                                                 org.slf4j.Logger log)

  Deprecated.

  This method helps resolve if the deprecated "update.processor" request parameter is used and logs a warning if it is. In a future version, this method will be removed and Solr will assume "update.chain" and not look for "update.processor"

  Parameters:
    `params` - an instance of SolrParams from the request
    `log` - an instance of a slf4j logger to log a warning in case of deprecated param usage
  Returns:
    null if neither is specified, else the value of the param specified

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD