One more Solr step by step setup tutorial – Part II of II


Finally, I am getting to do the second part of this tutorial!

Configuring Solr

Picking up where we left off, we need to modify solrconfig.xml and schema.xml to suit our needs.

We’ll start with solrconfig.xml. Open the file in an editor and do a search for “data”, which should take you to ${}. Set the directory to wherever you want the Solr index to be built (the index is built by “feeding” Solr with data – so you need enough disk space to store the index…). There are many other settings you can change in this file, but for now we’ll just change this one. Feel free to lookup the detail on the other settings on the official Solr wiki.

Next we’ll change the schema. The schema.xml file is also full of interesting stuff, but to ease into it we will first pay attention ot the fact that it is made of two basic parts: the types section which is used to define basic types for the facets and the fields section which is used to define that actual facets in your data.

My schema.xml is setup to accept some basic book data. And a corresponding sample data file would look something like this. So you need to edit the schema file to meet your need. Some of this will require trying out different types. Also pay attention to the uniqueKey parameter which identifies a unique key for your Solr documents. Once you have a schema and and data file, we can move on to loading the data.

Here are my solrconfig.xml and schema.xml

Loading data into Solr

There are millions of ways to load data into Solr. Many of which involve using libraries that create an easy interface to Solr depending on your programming language of choice (there are PHP ones, C#, Python, etc.). Our example solr_data_post.php, is a bit of PHP code that does not use a abstraction API, so it directly loads data from a mySQL table (you should be able to create your own from reading the code) into Solr using an HTTP POST. The file also uses solr_config.php which you should modify to match your parameters.

Retrieving data from Solr

Our final step, and again a myriad of ways to do this many involving abstraction APIs to shield you from hand crafting Solr requests. But again in the accompanying PHP code solr_search.php, I am not using an abstraction API. This little piece of code is a rudimentary search interface. As you play with different parameters you will see that the GET request sent to Solr changes. Again, go to the official Solr wiki for a full detail of how to query a Solr engine.

Voila! That’s it. I hope you found this tutorial useful. If you did, please “Like” it and/or leave me some comments.


5 thoughts on “One more Solr step by step setup tutorial – Part II of II

  1. while i am working thorugh this a quick note on the schema file up there. i copied it from the pdf and got a bunch of “!” so i used the find and replace commance and replaced them with ” “. ill let you know how that wnet.

    • Samuel, thanks for the note. Yeah, it is funky. I just tried and got the same thing (for me the series of “!” are on empty lines). I posted those as PDF because I am not sure I an post these in any other format. Let me know if you run into any other issue.

  2. Thanks a lot for the great tutorial. This tutorial is more about how to set up a development environment. Can you also offer a tutorial about how to deploy? like only move all the necessary files (maybe the war file?) to the deployed server?

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.