| java.lang.Object org.apache.solr.util.SolrPluginUtils
SolrPluginUtils | public class SolrPluginUtils (Code) | | 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.
|
Inner Class :public static class DisjunctionMaxQueryParser extends SolrQueryParser | |
Inner Class :public static class IdentityRegenerator implements CacheRegenerator | |
Method Summary | |
static int | calculateMinShouldMatch(int optionalClauseCount, String spec) | public static DocList | doSimpleQuery(String sreq, SolrIndexSearcher searcher, IndexSchema schema, int start, int limit) | public static NamedList | doStandardDebug(SolrQueryRequest req, String userQuery, Query query, DocList results, CommonParams params)
Returns a NamedList containing many "standard" pieces of debugging
information. | public static NamedList | doStandardDebug(SolrQueryRequest req, String userQuery, Query query, DocList results)
Returns a NamedList containing many "standard" pieces of debugging
information. | 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. | public static boolean | getBooleanParam(SolrQueryRequest req, String param, boolean def) Treats parameter value as a boolean. | public static NamedList | getExplainList(Query query, DocList docs, SolrIndexSearcher searcher, IndexSchema schema) Generates an list of Explanations for each item in a list of docs. | public static Number | getNumberParam(SolrQueryRequest req, String param, Number def) Treats the param value as a Number, returns the default if nothing is
there or if it's not a number. | public static String | getParam(SolrQueryRequest req, String param, String def) Returns the param, or the default if it's empty or not specified. | public static Sort | getSort(SolrQueryRequest req) | public 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. | public static void | optimizePreFetchDocs(DocList docs, Query query, SolrQueryRequest req, SolrQueryResponse res) 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.
| 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. | 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. | public static List<Query> | parseFilterQueries(SolrQueryRequest req) | public static List<Query> | parseFuncs(IndexSchema s, String in) Given a string containing functions with optional boosts, returns
an array of Queries representing those functions with the specified
boosts. | public static List<Query> | parseQueryStrings(SolrQueryRequest req, String[] queries) Turns an array of query strings into a List of Query objects. | public static CharSequence | partialEscape(CharSequence s) | public static void | setDefaults(SolrQueryRequest req, SolrParams defaults) Set defaults on a SolrQueryRequest. | public static void | setDefaults(SolrQueryRequest req, SolrParams defaults, SolrParams appends, SolrParams invariants) Set default-ish params on a SolrQueryRequest. | 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. | public static int | setReturnFields(SolrQueryRequest req, SolrQueryResponse res) | public static int | setReturnFields(String fl, SolrQueryResponse res) Given a space seperated list of field names, sets the field list on the
SolrQueryResponse. | public static String[] | split(String value) Split a value that may contain a comma, space of bar separated list. | 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. |
FL | public static String FL(Code) | | standard param for field list
|
doStandardDebug | public static NamedList doStandardDebug(SolrQueryRequest req, String userQuery, Query query, DocList results, CommonParams params) throws IOException(Code) | |
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 Parameters: userQuery - the users query as a string, after any basicpreprocessing has been done Parameters: query - the query built from the userQuery(and perhaps other clauses) that identifies the mainresult set of the response. Parameters: results - the main result set of the response |
doStandardDebug | public static NamedList doStandardDebug(SolrQueryRequest req, String userQuery, Query query, DocList results) throws IOException(Code) | |
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 Parameters: userQuery - the users query as a string, after any basicpreprocessing has been done Parameters: query - the query built from the userQuery(and perhaps other clauses) that identifies the mainresult set of the response. Parameters: results - the main result set of the response |
flattenBooleanQuery | public static void flattenBooleanQuery(BooleanQuery to, BooleanQuery from)(Code) | | 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.
|
getBooleanParam | public static boolean getBooleanParam(SolrQueryRequest req, String param, boolean def)(Code) | | Treats parameter value as a boolean. The string 'false' is false;
any other non-empty string is true.
|
getExplainList | public static NamedList getExplainList(Query query, DocList docs, SolrIndexSearcher searcher, IndexSchema schema) throws IOException(Code) | | Generates an list of Explanations for each item in a list of docs.
Parameters: query - The Query you want explanations in the context of Parameters: docs - The Documents you want explained relative that query |
getNumberParam | public static Number getNumberParam(SolrQueryRequest req, String param, Number def)(Code) | | Treats the param value as a Number, returns the default if nothing is
there or if it's not a number.
|
getSort | public static Sort getSort(SolrQueryRequest req)(Code) | | Determines the correct Sort based on the request parameter "sort"
null if no sort is specified. |
numDocs | public static int numDocs(SolrIndexSearcher s, Query q, Query f) throws IOException(Code) | | SolrIndexSearch.numDocs(Query,Query) freaks out if the filtering
query is null, so we use this workarround.
|
optimizePreFetchDocs | public static void optimizePreFetchDocs(DocList docs, Query query, SolrQueryRequest req, SolrQueryResponse res) throws IOException(Code) | | 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.
|
parseFieldBoosts | public static Map<String, Float> parseFieldBoosts(String in)(Code) | | 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" Map of fieldOne => 2.3, fieldTwo => null, fieldThree => -0.4 |
parseFieldBoosts | public static Map<String, Float> parseFieldBoosts(String[] fieldLists)(Code) | | 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"} Map of fieldOne => 2.3, fieldThree => -0.4 |
parseFilterQueries | public static List<Query> parseFilterQueries(SolrQueryRequest req) throws ParseException(Code) | | Builds a list of Query objects that should be used to filter results
See Also: SolrParams.FQ null if no filter queries |
parseFuncs | public static List<Query> parseFuncs(IndexSchema s, String in) throws ParseException(Code) | | 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.
See Also: SolrPluginUtils.parseFieldBoosts |
parseQueryStrings | public static List<Query> parseQueryStrings(SolrQueryRequest req, String[] queries) throws ParseException(Code) | | Turns an array of query strings into a List of Query objects.
null if no queries are generated |
partialEscape | public static CharSequence partialEscape(CharSequence s)(Code) | | Escapes all special characters except '"', '-', and '+'
See Also: QueryParser.escape |
setDefaults | public static void setDefaults(SolrQueryRequest req, SolrParams defaults)(Code) | | 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)(Code) | | 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 Parameters: defaults - values to be used if no values are specified in the request params Parameters: 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. Parameters: invariants - values which will be used instead of any request, or default values, regardless of context. |
setMinShouldMatch | public static void setMinShouldMatch(BooleanQuery q, String spec)(Code) | | 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"
|
setReturnFields | public static int setReturnFields(String fl, SolrQueryResponse res)(Code) | | Given a space seperated list of field names, sets the field list on the
SolrQueryResponse.
bitfield of SolrIndexSearcher flags that need to be set |
split | public static String[] split(String value)(Code) | | Split a value that may contain a comma, space of bar separated list.
|
stripUnbalancedQuotes | public static CharSequence stripUnbalancedQuotes(CharSequence s)(Code) | | 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.
|
|
|