<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/solrium-1-0-working-with-solr-from-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://ropensci.org/technotes/2017/11/08/solrium-solr-r/"> rOpenSci - open tools for open science</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Nearly 4 years ago I wrote on this blog about an R package <a rel="nofollow" href="https://github.com/ropensci/solr" target="_blank">solr</a> for working with the database <a rel="nofollow" href="https://lucene.apache.org/solr/" target="_blank">Solr</a>. Since then we’ve created a refresh of that package in the <a rel="nofollow" href="https://github.com/ropensci/solrium" target="_blank">solrium</a> package. Since <code>solrium</code> first hit CRAN about two years ago, users have raised a number of issues that required breaking changes. Thus, this blog post is about a major version bump in <code>solrium</code>.</p>
<p></p>
<h2>What is Solr?</h2>
<p>Solr is a “search platform” – a NoSQL database – data is organized by so called documents that are xml/json/etc blobs of text. Documents are nested within either collections or cores (depending on the mode you start Solr in). Solr makes it easy to search for documents, with a huge variety of parameters, and a number of different data formats (json/xml/csv). Solr is similar to <a rel="nofollow" href="https://www.elastic.co/products/elasticsearch" target="_blank">Elasticsearch</a> (see our Elasticsearch client <a rel="nofollow" href="https://github.com/ropensci/elastic" target="_blank">elastic</a>) – and was around before it. Solr in my opinion is harder to setup than Elasticsearch, but I don’t claim to be an expert on either.</p>
<p></p>
<h2>Vignettes</h2>
<ul>
<li><a rel="nofollow" href="https://cran.rstudio.com/web/packages/solrium/vignettes/search.html" target="_blank">Solr Search with solrium</a></li>
<li><a rel="nofollow" href="https://cran.rstudio.com/web/packages/solrium/vignettes/local_setup.html" target="_blank">Local Solr setup</a></li>
<li><a rel="nofollow" href="https://cran.rstudio.com/web/packages/solrium/vignettes/document_management.html" target="_blank">Document management</a></li>
<li><a rel="nofollow" href="https://cran.rstudio.com/web/packages/solrium/vignettes/cores_collections.html" target="_blank">Cores/collections management</a></li>
</ul>
<h2>Noteable features</h2>
<ul>
<li>Added in v1, you can now work with many connection objects to different Solr instances.</li>
<li>Methods for the major search functionalities: search, highlight, stats, mlt, group, and facet. In addition, a catch all function <code>all</code> to combine all of those.</li>
<li>Comprehensive coverage of the Solr HTTP API</li>
<li>Can coerce data from Solr API into data.frame’s when possible</li>
</ul>
<h2>Setup</h2>
<p>Install <code>solrium</code></p>
<pre><code>install.packages(&quot;solrium&quot;)
</code></pre>
<p>Or get the development version:</p>
<pre><code>devtools::install_github(&quot;ropensci/solrium&quot;)
</code></pre>
<pre><code>library(solrium)
</code></pre>
<p></p>
<h2>Initialize a client</h2>
<p>A big change in <code>v1</code> of <code>solrium</code> is <code>solr_connect</code> has been replaced by <code>SolrClient</code>. Now you create an <code>R6</code> connection object with <code>SolrClient</code>, then you can call methods on that <code>R6</code> object, <strong>OR</strong> you can pass the connection object to functions.</p>
<p>By default, <code>SolrClient$new()</code> sets connections details for a Solr instance that’s running on <code>localhost</code>, and on port <code>8983</code>.</p>
<pre><code>(conn &lt;- SolrClient$new())
</code></pre>
<pre><code>#> </code></pre>