- OSX Mountain Lion 10.8.4
- SOLR 4.4.0
- Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
The easiest way to install solr is by using homebrew
$ brew install solr
brew will automatically download all files needed for our Solr, enjoy your coffee and wait for a couple of minutes until it’s completed.
Do you want to test if our installation is completed? Fortunately, there is an example directory provided from Apache Solr to test our configuration right away. But first we have to run it before insert/update the data.
$ cd /usr/local/Cellar/solr/4.4.0/libexec/example/
$ java -jar start.jar
you will see lots of dumping message in your console, do not panic and it’s normal (if there is an error just fix that), we just run our first Solr application. Now test our Solr using Web Browser, heads to http://localhost:8983/solr/#/
you will see this screen in your browser
Fresh Solr do not contain any data (the term is Document), for this tutorial we will try to insert some example data to our server (you don’t have to do this in production server)
$ cd /usr/local/Cellar/solr/4.4.0/libexec/example/exampledocs/
$ ./post.sh vidcard.xml
Within file post.sh, the script will call url http://localhost:8983/solr/update using curl to post xml data from file vidcard.xml
when importing data completed and no errors, this is the message
Rikis-MacBook-Pro:exampledocs risnandar$ ./post.sh vidcard.xml
Posting file vidcard.xml to http://localhost:8983/solr/update
<?xml version=”1.0″ encoding=”UTF-8″?>
<lst name=”responseHeader”><int name=”status”>0</int><int name=”QTime”>103</int></lst>
<?xml version=”1.0″ encoding=”UTF-8″?>
<lst name=”responseHeader”><int name=”status”>0</int><int name=”QTime”>68</int></lst>
Let’s try to check our imported data using Web Browser, try this url to fetch all data in our Solr
when you see these data, it means your Solr server is working and running.
Since we’re using test data in our Solr, let’s delete all records by issuing this command:
$ curl http://localhost:8983/solr/update -H “Content-type: text/xml” –data-binary ‘<delete><query>*:*</query></delete>’
after that we also have to commit our update:
$ curl http://localhost:8983/solr/update -H “Content-type: text/xml” –data-binary ‘<commit />’
or you can use web browser
now our tables is emptied, try to access the previous url
Configuring Custom Solr XML
Enough with the sample, now we have to create our own XML configuration when starting the SOLR for our application. We can halt our example Solr by hitting Ctrl-C in command line to stop the job.
To create our custom directory to hold our custom Solr XML, you must create directory with the structure like this:
this is my configuration, please change the directory name with your own, and you may want to add directory ‘conf’ with version control just for backup
$ mkdir /Users/risnandar/Documents/htdocs/blanjamudah/solrblanjamudah
$ mkdir /Users/risnandar/Documents/htdocs/blanjamudah/solrblanjamudah/conf
$ mkdir /Users/risnandar/Documents/htdocs/blanjamudah/solrblanjamudah/data
let’s copy the required files from previous example
$ cd /usr/local/Cellar/solr/4.4.0/libexec/example/solr/collection1/conf/
$ cp schema.xml solrconfig.xml currency.xml elevate.xml lang protwords.txt stopwords.txt synonyms.txt /Users/risnandar/Documents/htdocs/blanjamudah/solrblanjamudah/conf/
run our Custom Solr
$ solr /Users/risnandar/Documents/htdocs/blanjamudah/solrblanjamudah
after it’s running, you can configure your custom XML by modifying files in ‘conf’ directory. Don’t forget to restart solr after make any changes.
Do we need Tomcat?
New applications means more CPU and memory, i am not using Tomcat for this Solr Installation. In my local / development server i am not doing anything with the firewall, but in Production Server, for security sakes you should restrict port 8983 to your IP only or block from any remote location, it’s much much safer to only allow from localhost.
Now it’s your job to import the xml file from your application to Solr. There is several way to achieve that such as:
- Create daily cron job with command line php (cli) to load required records then post the data to Solr
- Import all existing records to Solr, then create Live updating in your application, when you save,change,delete records, you also post the data to Solr
Mine is using approach number 2.