Thursday, February 28, 2013

Step-by-step tutorial on the installation of Apache Solr


This post is a simple, detailed, and step-by-step tutorial on how to install Apache Solr


Step 1: Download solr-4.1.0 from http://www.apache.org/dist/lucene/solr/4.1.0/solr-4.1.0.zip

Step 2: Unzip solr-4.1.0 to a folder. Suppose the path of the folder is D:/solr-4.1.0

Step 3: Execute cmd.exe

Step 4: Enter command: cd /d D:  to change disk

Step 5: Enter command: cd D:/solr-4.1.0/example/

This step is to change to the directory of the start.jar.

Step 6: Enter command: java -jar start.jar to start Apache Solr.

If the resulting screen is without error messages like this, it is successful.



After entering this command, do not shutdown the cmd window or enter Ctrl C to close the server now.

Step 7: Execute cmd.exe again to open another cmd window

Step 8: In the new cmd window, enter command: cd /d D:

Step 9: In the same cmd window, enter cd D:/solr-4.1.0/example/exampledocs

This step is to change to the directory of the post.jar

Step 10: In the same window, enter java -Dauto -Drecursive -jar post.jar D:/solr-4.1.0/example/exampledocs

This step is to index all Solr documents inside the folder D:/solr-4.1.0/example/exampledocs
with the post.jar. If the resulting screen is similar to this, this step is successful.

 


After this step is done, the Solr documents inside D:/solr-4.1.0/example/exampledocs are successfully indexed. Then you can quickly search the indexed documents with Solr queries.

For example, you can search documents with "George" in the author field and "game" in the game field by this url
http://localhost:8983/solr/collection1/select?q=author:George%20AND%20name:game&wt=xml and get the following Solr document:




-------



P.S: Some commands for Solr can be looked up by "java -jar post.jar -h." The post.jar is inside D:/solr-4.1.0/example/exampledocs. The following are example commands:

  java -jar post.jar *.xml

  java -Ddata=args  -jar post.jar '<delete><id>42</id></delete>'

  java -Ddata=stdin -jar post.jar < hd.xml

  java -Ddata=web -jar post.jar http://example.com/

  java -Dtype=text/csv -jar post.jar *.csv

  java -Dtype=application/json -jar post.jar *.json

  java -Durl=http://localhost:8983/solr/update/extract -Dparams=literal.id=a -Dt                   ype=application/pdf -jar post.jar a.pdf

  java -Dauto -jar post.jar *

  java -Dauto -Drecursive -jar post.jar afolder

Furthermore, you can install Cygwin and the curl package and then index documents with a curl command:
curl 'http://localhost:8983/solr/update/json?commit=true' --data-binary @books.json -H 'Content-type:application/json'



7 comments:

  1. Thanks a lot!!!

    Change

    D:/solr-4.1.0/exampledocs

    to

    D:/solr-4.1.0/example/exampledocs

    ReplyDelete
  2. Thanks Anonymous. I modified this post and ChangeD:/solr-4.1.0/exampledocs to D:/solr-4.1.0/example/exampledocs.

    ReplyDelete
  3. Hi, thanks for sharing this. Its nice article. But I found a better one.. You can check it here.. posting it here so others can find it too:

    http://www.nopaccelerate.com/wiki/installing-apache-solr/

    and

    http://www.nopaccelerate.com/wiki/configuring-apache-solr-to-use-with-nopaccelerate/

    Thanks, all the best.

    Harry

    ReplyDelete
  4. Hello Anonymous:

    Thanks for your suggestion.

    Tom

    ReplyDelete
  5. Hey thanks,

    that was really awesome...

    ReplyDelete
  6. Thank you very much. Nicely explained.

    ReplyDelete