SolrQuery-class {rsolr} | R Documentation |
SolrQuery
Description
The SolrQuery
object represents a query to be sent to a
SolrCore
. This is a low-level interface to query
construction but will not be useful to most users. The typical reason
to directly manipulate a query would be to batch more operations than is
possible with the high-level SolrFrame
, e.g., combining
multiple aggregations.
Details
A SolrQuery
API borrows many of the same verbs from the base R
API, including subset
, transform
,
sort
, xtabs
, head
,
tail
, rev
, etc.
The typical workflow is to construct a query, perform various
manipulations, and finally retrieve a result by passing the query to a
SolrCore
, typically via the docs
or facets
functions.
Accessors
-
params(x), params(x) <- value
: Gets/sets the parameters of the query, which roughly correspond to the parameters of a Solr “select” request. The only reason to manipulate the underlying query parameters is to either initiate a headache or to do something really tricky with Solr, which implies the former.
Querying
subset(x, subset, select, fields, select.from = character())
: Behaves like the basesubset
, with some extensions. Thefields
argument is exclusive withselect
, and should be a character vector of field names, potentially with wildcards. Theselect.from
argument gives the names that are filtered byselect
, sinceSolrQuery
is not associated with anySolrCore
, and thus does not know the field set (in the future, we might use laziness to avoid this problem).searchDocs(x, q)
: Performs a conventional document search using the query stringq
. The main difference to filtering (subset
) is that (by default) Solr will order the result by score, i.e., how well each document matches the query.
Constructor
-
SolrQuery(expr)
: Constructs a newSolrQuery
instance. Ifexpr
is non-missing, it is passed tosubset
and thus serves as an initial restriction.
Faceting
The Solr facet component counts documents and calculates statistics on a group-wise basis.
facet(x, by, ..., useNA=FALSE, sort=NULL, decreasing=FALSE, limit=NA_integer_)
: Returns a query that will compute the number of documents in each group, where the grouping is given asby
, typically a formula, orNULL
for global aggregation. Arguments in ... are quoted and should be expressions that summarize fields, or mathematical combinations of fields. The names of the statistics are taken from the argument names; if a name is omitted, a best guess is made from the expression. IfuseNA
isTRUE
, statistics and counts are computed for the bin where documents have a missing value for one the grouping variables. Ifsort
is non-NULL, it should name a statistic by which the results should be sorted. This is mostly useful in conjunction if alimit
is specified, so that only the top-N statistics are returned.The formula should consist of Solr field names, or calls that evaluate to logical and refer to one or more Solr fields. If the latter, the results are grouped by
TRUE
,FALSE
and (optionally)NA
for that term. As a special case, a term can be a call tocut
on any numeric or date field, which will group by bin.
Grouping
The Solr grouping component causes results to be returned nested into
groups. The main use case would be to restrict to the first or last N
documents in each group. This functionality is not related to
aggregation; see facet
.
group(x, by, limit = .Machine$integer.max, offset = 0L, env = emptyenv())
: Returns the grouping ofx
according toby
, which might be a formula, or an expression that evaluates (withinenv
) to a factor. The current sort specification applies within the groups, and any subsequent sorting applies to the groups themselves, by using the maximum value within the each group. Only the toplimit
documents, starting after the firstoffset
, are returned from each group. Restricting that limit is probably the main reason to use this functionality.
Coercion
These two functions are very low-level; users should almost never need to call these.
-
translate(x, target, core)
: Translates the queryx
into the language of Solr, wherecore
specifies the destinationSolrCore
. Thetarget
argument should be missing. -
as.character(x)
: Converts the query into a string to be sent to Solr. Remember to translate first, if necessary.
Author(s)
Michael Lawrence
See Also
SolrFrame
, the recommended high-level interface
for interacting with Solr
SolrCore
, which gives an example of constructing
and evaluating a query