SolrQuery-class | R Documentation |
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.
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.
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.
subset(x, subset, select, fields, select.from =
character())
: Behaves like the base subset
, with
some extensions. The fields
argument is exclusive with
select
, and should be a character vector of field names,
potentially with wildcards. The select.from
argument
gives the names that are filtered by select
, since
SolrQuery
is not associated with any SolrCore
, 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 string q
. 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.
SolrQuery(expr)
:
Constructs a new SolrQuery
instance. If expr
is
non-missing, it is passed to subset
and thus serves as an
initial restriction.
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 as by
, typically a formula, or
NULL
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. If useNA
is
TRUE
, statistics and counts are computed for the bin
where documents have a missing value for one the grouping
variables. If sort
is non-NULL, it should name a
statistic by which the results should be sorted. This is mostly
useful in conjunction if a limit
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 to cut
on any numeric or date field, which
will group by bin.
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 of x
according to by
, which might be a formula, or an
expression that evaluates (within env
) 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 top
limit
documents, starting after the first offset
,
are returned from each group. Restricting that limit is probably
the main reason to use this functionality.
These two functions are very low-level; users should almost never need to call these.
translate(x, target, core)
: Translates the query x
into the language of Solr, where core
specifies the
destination SolrCore
. The target
argument should be
missing.
as.character(x)
:
Converts the query into a string to be sent to Solr. Remember to
translate first, if necessary.
Michael Lawrence
SolrFrame
, the recommended high-level interface
for interacting with Solr
SolrCore
, which gives an example of constructing
and evaluating a query
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.