public class SolrPluginUtils extends Object
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
UNKNOWN_VALUE |
Constructor and Description |
---|
SolrPluginUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copyNamedListIntoArrayByDocPosInResponse(NamedList namedList,
Map<Object,ShardDoc> resultIds,
Map.Entry<String,Object>[] destArr)
Copies the given
namedList assumed to have doc uniqueKey keyed data into destArr
at the position of the document in the response. |
static DocList |
doSimpleQuery(String sreq,
SolrQueryRequest req,
int start,
int limit)
Executes a basic query
|
static NamedList |
doStandardDebug(SolrQueryRequest req,
String userQuery,
Query query,
DocList results,
boolean dbgQuery,
boolean dbgResults)
Returns a NamedList containing many "standard" pieces of debugging
information.
|
static void |
doStandardQueryDebug(SolrQueryRequest req,
String userQuery,
Query query,
boolean dbgQuery,
NamedList dbg) |
static void |
doStandardResultsDebug(SolrQueryRequest req,
Query query,
DocList results,
boolean dbgResults,
NamedList dbg) |
static NamedList<NamedList<Object>> |
explanationsToNamedLists(NamedList<Explanation> explanations) |
static NamedList<Object> |
explanationToNamedList(Explanation e) |
static void |
flattenBooleanQuery(BooleanQuery.Builder to,
BooleanQuery from)
Recursively walks the "from" query pulling out sub-queries and
adding them to the "to" query.
|
static Set<String> |
getDebugInterests(String[] params,
ResponseBuilder rb) |
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 String |
getRequestPurpose(Integer reqPurpose)
Given the integer purpose of a request generates a readable value corresponding
the request purposes (there can be more than one on a single request).
|
static Sort |
getSort(SolrQueryRequest req)
Determines the correct Sort based on the request parameter "sort"
|
static void |
invokeSetters(Object bean,
Iterable<Map.Entry<String,Object>> initArgs) |
static void |
invokeSetters(Object bean,
Iterable<Map.Entry<String,Object>> initArgs,
boolean lenient) |
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(ResponseBuilder rb,
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<FieldParams> |
parseFieldBoostsAndSlop(String[] fieldLists,
int wordGrams,
int defaultSlop)
/**
Like
parseFieldBoosts(java.lang.String) , but allows for an optional slop value prefixed by "~". |
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 <T> NamedList<T> |
removeNulls(Map.Entry<String,T>[] entries,
NamedList<T> dest)
Adds to
dest all the not-null elements of entries that have non-null names |
static void |
setDefaults(SolrQueryRequest req,
SolrParams defaults,
SolrParams appends,
SolrParams invariants)
Set default-ish params on a SolrQueryRequest.
|
static void |
setDefaults(SolrRequestHandler handler,
SolrQueryRequest req,
SolrParams defaults,
SolrParams appends,
SolrParams invariants) |
static void |
setMinShouldMatch(BooleanQuery.Builder q,
String spec) |
static void |
setMinShouldMatch(BooleanQuery.Builder q,
String spec,
boolean mmAutoRelax)
Checks the number of optional clauses in the query, and compares it
with the specification string to determine the proper value to use.
|
static BooleanQuery |
setMinShouldMatch(BooleanQuery q,
String spec) |
static BooleanQuery |
setMinShouldMatch(BooleanQuery q,
String spec,
boolean mmAutoRelax) |
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 returns its
input.
|
static CharSequence |
stripUnbalancedQuotes(CharSequence s)
Returns its input if there is an even (ie: balanced) number of
'"' characters -- otherwise returns a String in which all '"'
characters are striped out.
|
protected static final String UNKNOWN_VALUE
public static void setDefaults(SolrQueryRequest req, SolrParams defaults, SolrParams appends, SolrParams invariants)
req
- The request whose params we are interested idefaults
- values to be used if no values are specified in the request paramsappends
- 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.public static void setDefaults(SolrRequestHandler handler, SolrQueryRequest req, SolrParams defaults, SolrParams appends, SolrParams invariants)
public static int numDocs(SolrIndexSearcher s, Query q, Query f) throws IOException
IOException
public static String[] split(String value)
public static void optimizePreFetchDocs(ResponseBuilder rb, DocList docs, Query query, SolrQueryRequest req, SolrQueryResponse res) throws IOException
IOException
public static Set<String> getDebugInterests(String[] params, ResponseBuilder rb)
public static NamedList doStandardDebug(SolrQueryRequest req, String userQuery, Query query, DocList results, boolean dbgQuery, boolean dbgResults) throws IOException
Returns a NamedList containing many "standard" pieces of debugging information.
req
- the request we are dealing withuserQuery
- the users query as a string, after any basic
preprocessing has been donequery
- 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 responseIOException
- if there was an IO errorpublic static void doStandardQueryDebug(SolrQueryRequest req, String userQuery, Query query, boolean dbgQuery, NamedList dbg)
public static void doStandardResultsDebug(SolrQueryRequest req, Query query, DocList results, boolean dbgResults, NamedList dbg) throws IOException
IOException
public static NamedList<Object> explanationToNamedList(Explanation e)
public static NamedList<NamedList<Object>> explanationsToNamedLists(NamedList<Explanation> explanations)
public static NamedList<Explanation> getExplanations(Query query, DocList docs, SolrIndexSearcher searcher, IndexSchema schema) throws IOException
query
- The Query you want explanations in the context ofdocs
- The Documents you want explained relative that queryIOException
public static DocList doSimpleQuery(String sreq, SolrQueryRequest req, int start, int limit) throws IOException
IOException
public static Map<String,Float> parseFieldBoosts(String in)
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.
in
- a String like "fieldOne^2.3 fieldTwo fieldThree^-0.4"public static Map<String,Float> parseFieldBoosts(String[] fieldLists)
parseFieldBoosts(String)
, but parses all the strings
in the provided array (which may be null).fieldLists
- an array of Strings eg. {"fieldOne^2.3", "fieldTwo", fieldThree^-0.4}
public static List<FieldParams> parseFieldBoostsAndSlop(String[] fieldLists, int wordGrams, int defaultSlop)
parseFieldBoosts(java.lang.String)
, but allows for an optional slop value prefixed by "~".fieldLists
- - an array of Strings eg. {"fieldOne^2.3", "fieldTwo", fieldThree~5^-0.4}
wordGrams
- - (0=all words, 2,3 = shingle size)defaultSlop
- - the default slop for this parampublic static void setMinShouldMatch(BooleanQuery.Builder q, String spec, boolean mmAutoRelax)
If mmAutoRelax=true, we'll perform auto relaxation of mm if tokens are removed from some but not all DisMax clauses, as can happen when stopwords or punctuation tokens are removed in analysis.
Details about the specification format can be found here
A few important notes...
:TODO: should optimize the case where number is same as clauses to just make them all "required"
q
- The query as a BooleanQuery.Builderspec
- The mm specmmAutoRelax
- whether to perform auto relaxation of mm if tokens are removed from some but not all DisMax clausespublic static void setMinShouldMatch(BooleanQuery.Builder q, String spec)
public static BooleanQuery setMinShouldMatch(BooleanQuery q, String spec)
public static BooleanQuery setMinShouldMatch(BooleanQuery q, String spec, boolean mmAutoRelax)
public static void flattenBooleanQuery(BooleanQuery.Builder to, BooleanQuery from)
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.
public static CharSequence partialEscape(CharSequence s)
public static CharSequence stripIllegalOperators(CharSequence s)
public static CharSequence stripUnbalancedQuotes(CharSequence s)
public static <T> NamedList<T> removeNulls(Map.Entry<String,T>[] entries, NamedList<T> dest)
dest
all the not-null elements of entries
that have non-null namespublic static void copyNamedListIntoArrayByDocPosInResponse(NamedList namedList, Map<Object,ShardDoc> resultIds, Map.Entry<String,Object>[] destArr)
namedList
assumed to have doc uniqueKey keyed data into destArr
at the position of the document in the response. destArr is assumed to be the same size as
resultIds
is. resultIds
comes from ResponseBuilder.resultIds
. If the doc key
isn't in resultIds
then it is ignored.
Note: most likely you will call removeNulls(Map.Entry[], NamedList)
sometime after calling this.public static Sort getSort(SolrQueryRequest req)
public static List<Query> parseQueryStrings(SolrQueryRequest req, String[] queries) throws SyntaxError
SyntaxError
public static void invokeSetters(Object bean, Iterable<Map.Entry<String,Object>> initArgs)
public static void invokeSetters(Object bean, Iterable<Map.Entry<String,Object>> initArgs, boolean lenient)
public static String getRequestPurpose(Integer reqPurpose)
reqPurpose
- Numeric request purposeCopyright © 2000-2017 Apache Software Foundation. All Rights Reserved.