SolrCore-class {rsolr} | R Documentation |
SolrCore
Description
The SolrCore
object represents a core hosted by a Solr
instance. A core is essentially a queryable collection of documents
that share the same schema. It is usually not necessary to interact
with a SolrCore
directly.
Details
The typical usage (by advanced users) would be to construct a custom
SolrQuery
and execute it via the docs
,
facets
or (the very low-level) eval
methods.
Accessor methods
In the code snippets below, x
is a SolrCore
object.
name(x)
: Gets the name of the core (specified by the schema).ndoc(x, query = SolrQuery())
: Gets the number of documents in the core, given thequery
restriction.schema(x)
: Gets theSolrSchema
satisfied by all documents in the core.fieldNames(x, query = NULL, onlyStored = FALSE, onlyIndexed = FALSE, includeStatic = FALSE)
: Gets the field names, given any restriction and/or transformation inquery
, which is aSolrQuery
or a character vector of field patterns. TheonlyIndexed
andonlyStored
arguments restrict the fields to those indexed and stored, respectively (seeFieldInfo
for more details). SettingincludeStatic
toTRUE
ensures that all of the static fields in the schema are returned.version(x)
: Gets the version of the Solr instance hosting the core.
Constructor
-
SolrCore(uri, ...)
: Constructs a newSolrCore
instance, representing a Solr core located aturi
, which should be a string or aRestUri
object. If a string, then the ... are passed to theRestUri
constructor.
Reading
-
docs(x, query = SolrQuery(), as=c("list", "data.frame"))
: Get the documents selected byquery
, in the form indicated byas
, i.e., either a list or a data frame. -
read(x, ...)
: Just an alias fordocs
.
Summarizing
-
facets(x, by, ...)
: Gets theFacets
results as requested byby
, aSolrQuery
. The ... are passed down tofacets
onListSolrResult
. -
groupings(x, by, ...)
: Gets the list ofGrouping
objects as requested by the grouped queryby
. The ... are passed down togroupings
onListSolrResult
. -
ngroup(x)
: Gets the number of groupings that would be returned bygroupings
.
Updating
-
update(object, value, commit = TRUE, atomic = FALSE, ...)
: Load the documents invalue
(typically a list or data frame) into the SolrCore given byobject
. Ifcommit
isTRUE
, we request that Solr commit the changes to its index on disk, with arguments in...
fine-tuning the commit (seecommit
). Ifatomic
isTRUE
, then the existing documents are modified, rather than replaced, by the documents invalue
. -
delete(x, which = SolrQuery(), ...)
: Deletes the documents specified bywhich
(all by default), where the ... are passed down toupdate
. -
commit(x, waitSearcher=TRUE, softCommit=FALSE, expungeDeletes=FALSE, optimize=TRUE, maxSegments=if (optimize) 1L)
: Commits the changes to the Solr index; see the Solr documentation for the meaning of the parameters. -
purgeCache(x)
: Purges the client-side HTTP cache, which is useful if the Solr instance is using expiration-based HTTP caching and one needs to see the result of an update immediately.
Evaluation
-
eval(expr, envir, enclos)
: Evaluates the queryexpr
in the coreenvir
, ignoringenclos
. Unless otherwise requested by the query response type, the result should be returned as aListSolrResult
.
Coercion
-
as.data.frame(x, row.names=NULL, optional=FALSE, ...)
:
Author(s)
Michael Lawrence
See Also
SolrFrame
, the typical way to interact with a
Solr core.
Examples
solr <- TestSolr()
sc <- SolrCore(solr$uri)
name(sc)
ndoc(sc)
delete(sc)
docs <- list(
list(id="2", inStock=TRUE, price=2, timestamp_dt=Sys.time()),
list(id="3", inStock=FALSE, price=3, timestamp_dt=Sys.time()),
list(id="4", price=4, timestamp_dt=Sys.time()),
list(id="5", inStock=FALSE, price=5, timestamp_dt=Sys.time())
)
update(sc, docs)
q <- SolrQuery(id %in% as.character(2:4))
read(sc, q)
solr$kill()