2. 1. Installation of SOLR
1.1 Open console. Start install solr with jetty for web-server:
sudo apt-get -y install openjdk-7-jdk
cd /opt
wget http://archive.apache.org/dist/lucene/solr/4.7.2/solr-4.7.2.tgz
tar -xvf solr-4.7.2.tgz
cp -R solr-4.7.2/example /opt/solr
cd /opt/solr
java -jar start.jar
After this we can check if all works on http://YOUR_IP:8983/solr. After this we need to close app in console with
Ctrl+C.
3. 1. Installation of SOLR
1.2 Open console. Start configuring /etc/default/jetty:
nano /etc/default/jetty
Add this settings to this file:
NO_START=0
JAVA_OPTIONS="-Dsolr.solr.home=/opt/solr/solr $JAVA_OPTIONS"
JAVA_HOME=/usr/java/default
JETTY_HOME=/opt/solr
JETTY_USER=solr
JETTY_LOGS=/opt/solr/logs
Save file!
4. 1. Installation of SOLR
1.3 Open console. Start configuring /opt/solr/etc/jetty-logging.xml:
nano /opt/solr/etc/jetty-logging.xml
Add this settings to this file:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<!-- =============================================================== -->
<!-- Configure stderr and stdout to a Jetty rollover log file -->
<!-- this configuration file should be used in combination with -->
<!-- other configuration files. e.g. -->
<!-- java -jar start.jar etc/jetty-logging.xml etc/jetty.xml -->
<!-- =============================================================== -->
<Configure id="Server" class="org.mortbay.jetty.Server">
<New id="ServerLog" class="java.io.PrintStream">
<Arg>
<New class="org.mortbay.util.RolloverFileOutputStream">
<Arg><SystemProperty name="jetty.logs" default="."/>/yyyy_mm_dd.stderrout.log</Arg>
<Arg type="boolean">false</Arg>
<Arg type="int">90</Arg>
<Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT</Arg></Call></Arg>
<Get id="ServerLogName" name="datedFilename"/>
</New>
</Arg>
</New>
<Call class="org.mortbay.log.Log" name="info"><Arg>Redirecting stderr/stdout to <Ref id="ServerLogName"/></Arg></Call>
<Call class="java.lang.System" name="setErr"><Arg><Ref id="ServerLog"/></Arg></Call>
<Call class="java.lang.System" name="setOut"><Arg><Ref id="ServerLog"/></Arg></Call></Configure>
5. 1. Installation of SOLR
1.4 Open console. Create user ‘solr’ and give him access:
sudo useradd -d /opt/solr -s /sbin/false solr
sudo chown solr:solr -R /opt/solr
1.5 Open console. Download script for starting jetty automatically on system
start:
sudo wget -O /etc/init.d/jetty
http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/jetty-
distribution/src/main/resources/bin/jetty.sh
sudo chmod a+x /etc/init.d/jetty
sudo update-rc.d jetty defaults
6. 2. Preparing SOLR Core for Drupal
2.1 We need to create Solr core for our Drupal site, by default solr has one
core which is called ‘collection1’, so we can just create our core from this one:
cd /opt/solr/solr
mv collection1 drupal
cd drupal
And we need to rename core in file core.properties:
nano core.properties
7. 2. Preparing SOLR Core for Drupal
2.2 Replace all files with settings in drupal solr core for those that are in a base
of a module Search API Solr.
So, we should download module https://www.drupal.org/project/search_api_solr.
And replace all files which are based in /opt/solr/solr/drupal/conf/ for files which are in search_api_solr/solr-
conf/4.x/
After this we should restart jetty:
sudo /etc/init.d/jetty restart
8. 3. Preparing Drupal
3.1 Download modules which we need for our search which are based in
search API:
https://www.drupal.org/project/search_api
https://www.drupal.org/project/search_api_solr
https://www.drupal.org/project/facetapi
3.2 Enable next modules:
Search API, Search facets, Search views, Solr search
9. 3. Preparing Drupal
3.3 Create new Search api server:
Go to /admin/config/search/search_api and click ‘Add server’. After filling ‘Server name’ and ‘Server description’ you
should choose ‘solr service’ in ‘Service class’ field. After this you should change only ‘Solr path’ field, to ‘/solr/drupal’,
and click ‘Create server’.
If all works fine you would see something like this:
10. 3. Preparing Drupal
3.4 Create new Search api index:
Go to /admin/config/search/search_api and click ‘Add index’. After filling ‘Index name’ (in our case it will be nodes) and
‘Index description’ you should choose ‘node’ in ‘Item type’ field, and choose server in ‘Server’ field which you have
created, and click ‘Create Index’.
On this page you can choose fields which you want to show on search result:
11. 3. Preparing Drupal
on tab ‘view’ of our index (in our case it’s ‘nodes’) we can reindex all content:
If we want to see immediately our NEW content in solr we should reindex content.
12. 3. Preparing Drupal
3.5 Create new view with our Search index:
You should just choose your search index on view creation, and to work with it as with standart view:
13. 4. Facets API
4.1 Create new Facet:
In your search index you can enable facet to each field which you have added to your search index. So we will enable
facet for content type field:
14. 4. Facets API
4.2 Add Facet to view page:
So now you can add your Facet to page with search result view as a block which you can find on
admin/structure/block. In our case it’s something like this: