<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Passing Curiosity: Posts tagged solr</title>
    <link href="https://passingcuriosity.com/tags/solr/solr.xml" rel="self" />
    <link href="https://passingcuriosity.com" />
    <id>https://passingcuriosity.com/tags/solr/solr.xml</id>
    <author>
        <name>Thomas Sutton</name>
        
        <email>me@thomas-sutton.id.au</email>
        
    </author>
    <updated>2014-05-13T00:00:00Z</updated>
    <entry>
    <title>Drupal, Search API and Apache Solr with Homebrew on OS X</title>
    <link href="https://passingcuriosity.com/2014/drupal-search-api-solr-homebrew/" />
    <id>https://passingcuriosity.com/2014/drupal-search-api-solr-homebrew/</id>
    <published>2014-05-13T00:00:00Z</published>
    <updated>2014-05-13T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>Installing <a href="http://lucene.apache.org/solr/">Apache Solr</a> with <a href="http://brew.sh/">Homebrew</a> on OS X and using it
with the <a href="http://drupal.org/project/search_api">Search API</a> modules for <a href="https://drupal.org/">Drupal</a> is pretty easy.
This article will run through the process and includes a few tweaks to make
things more convenient for those like me, who do this on different projects
fairly regularly.</p>
<h2 id="installing-apache-solr">Installing Apache Solr</h2>
<p>Apache Solr is a bit of a monolith (if you use it like most people I’ve seen):
you just download it and unpack it somewhere. Indeed, this is exactly what the
homebrew formula does. Run this command to get it installed:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">brew</span> install solr</span></code></pre></div>
<p>It also includes a handy shell script to start Solr using a configuration
directory you specify on the command line. Alas, it <em>doesn’t</em> set a few
properties which would be nice to have available in our Solr configuration
files. But it <em>is</em> a very simple shell script, and we have text editors!</p>
<p>Edit the <code>solr</code> shell script brew installed (you can use <code>which solr</code> to find
it) and make it look like this:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/bin/sh</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="va">DIST_PATH</span><span class="op">=</span><span class="st">&quot;/usr/local/Cellar/solr/4.7.2/libexec/dist&quot;</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="va">CONTRIB_PATH</span><span class="op">=</span><span class="st">&quot;/usr/local/Cellar/solr/4.7.2/libexec/contrib&quot;</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="bu">[</span> <span class="ot">-z</span> <span class="st">&quot;</span><span class="va">$1</span><span class="st">&quot;</span> <span class="bu">]</span><span class="kw">;</span> <span class="cf">then</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>  <span class="bu">echo</span> <span class="st">&quot;Usage: $ solr path/to/config/dir&quot;</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>  <span class="bu">cd</span> /usr/local/Cellar/solr/4.7.2/libexec/example <span class="kw">&amp;&amp;</span> <span class="ex">java</span> <span class="at">-server</span> <span class="va">$JAVA_OPTS</span> <span class="dt">\</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">-Dsolr.solr.home</span><span class="op">=</span><span class="va">$1</span> <span class="dt">\</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>    <span class="st">&quot;-Dsolr.dist.dir=</span><span class="va">${DIST_PATH}</span><span class="st">&quot;</span> <span class="dt">\</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a>    <span class="st">&quot;-Dsolr.contrib.dir=</span><span class="va">${CONTRIB_PATH}</span><span class="st">&quot;</span> <span class="dt">\</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">-jar</span> start.jar</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a><span class="cf">fi</span></span></code></pre></div>
<p>(The <code>4.7.2</code> part will change depending on the version of Solr you have
installed; make sure it’s correct.)</p>
<p>We’ve adding two new properties specify where to find the JAR files, etc. that
come in the Solr distribution. We’ll use these when we’re tweaking the Solr
configuration files that come with the Drupal modules.</p>
<h2 id="installing-drupal">Installing Drupal</h2>
<p>Now that Solr is installed, start a new Drupal site and install the Search API
modules. I’m a command line person, so I do something like this:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="va">PROJECT_NAME</span><span class="op">=</span>searchdemo</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="va">PROJECT</span><span class="op">=</span><span class="st">&quot;</span><span class="va">${HOME}</span><span class="st">/Sites/</span><span class="va">${PROJECT_NAME}</span><span class="st">&quot;</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mkdir</span> <span class="at">-p</span> <span class="st">&quot;</span><span class="va">${PROJECT}</span><span class="st">&quot;</span></span></code></pre></div>
<p>Start a new Drupal project, and download and install the Search API module and
all its friends:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> <span class="st">&quot;</span><span class="va">${PROJECT}</span><span class="st">&quot;</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="ex">drush</span> dl drupal <span class="at">--drupal-project-rename</span><span class="op">=</span>htdocs</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> htdocs</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="ex">mysqladmin</span> create <span class="st">&quot;</span><span class="va">${PROJECT_NAME}</span><span class="st">&quot;</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="ex">drush</span> site-install <span class="at">--db-url</span><span class="op">=</span>mysql://me:password@localhost/<span class="va">${PROJECT_NAME}</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a><span class="ex">drush</span> en search_api search_api_solr search_api_attachments facetapi</span></code></pre></div>
<h2 id="building-a-solr-core-for-search-api">Building a Solr core for Search API</h2>
<p>Now lets create a new Solr core for Search API to use. We’ll start with one of
the example configurations that come with Solr (watch out for the Solr version
number in this path):</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cp</span> <span class="at">-a</span> /usr/local/Cellar/solr/4.7.2/libexec/example/solr <span class="st">&quot;</span><span class="va">${PROJECT}</span><span class="st">/solr&quot;</span></span></code></pre></div>
<p>This configuration includes a single Solr “core” called <code>collection1</code>. We’ll
duplicate that, then drop the Search API Solr configuration on top of it.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> <span class="st">&quot;</span><span class="va">${PROJECT}</span><span class="st">/solr/&quot;</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mkdir</span> <span class="at">-p</span> <span class="st">&quot;</span><span class="va">${PROJECT_NAME}</span><span class="st">/&quot;</span><span class="dt">{conf</span><span class="op">,</span><span class="dt">data}</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="fu">cp</span> <span class="at">-a</span> <span class="st">&quot;collection1/conf&quot;</span>/<span class="pp">*</span> <span class="st">&quot;</span><span class="va">${PROJECT_NAME}</span><span class="st">/conf/&quot;</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="fu">cp</span> <span class="at">-a</span> <span class="va">${PROJECT}</span>/htdocs/sites/all/modules/search_api_solr/solr-conf/4.x/<span class="pp">*</span> <span class="st">&quot;</span><span class="va">${PROJECT_NAME}</span><span class="st">/conf/&quot;</span></span></code></pre></div>
<p>Now to tweak it. First, give the new core it’s own name so that Solr can
identify it correctly:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">&quot;name=</span><span class="va">${PROJECT_NAME}</span><span class="st">&quot;</span> <span class="op">&gt;</span> <span class="st">&quot;</span><span class="va">${PROJECT_NAME}</span><span class="st">/core.properties&quot;</span></span></code></pre></div>
<p>Then update the <code>solrconfig.xml</code> file that came with Search API Solr to use the
<code>solr.dist.dir</code> and <code>solr.contrib.dir</code> properties we added to the <code>solr</code> shell
script above. Basically replace any mention of <code>../../dist/</code> in your
<code>solrconfig.xml</code> file with <code>${solr.dist.dir:../../dist/}</code>. This says “use the
configured value for <code>solr.dist.dir</code> or, if there isn’t one, <code>../../dist/</code>”. It
should already be done for <code>solr.contrib.dir</code> but you might like to double
check, just in case.</p>
<p>If you want to use any optional/non-core features you’ll need to update the
<code>&lt;lib&gt;</code> tags (these are the main places you’ll need to make the <code>solr.dist.dir</code>
change) to use the correct JAR file names.</p>
<p>I’ll be using the extraction functionality to index the content of PDF and
other files, so I needed to uncomment and correct the tag for
<code>solr-cell-\d.*\.jar</code>:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>&lt;<span class="kw">lib</span><span class="ot"> dir=</span><span class="st">&quot;${solr.dist.dir:../../../dist/}&quot;</span><span class="ot"> regex=</span><span class="st">&quot;solr-cell-\d.*\.jar&quot;</span> /&gt;</span></code></pre></div>
<h2 id="running-it">Running it</h2>
<p>Now go configure your Drupal site to use your new Apache Solr instance. You
should configure Search API to communicate with Solr at
<code>http://searchapi.dev:8983/solr/${PROJECT_NAME}</code> (you should put the real value
here, not the variable name). Then enable an index, configure it, and build
some search functionality!</p>]]></summary>
</entry>

</feed>
