You are on page 1of 20

APACHE SOLR

Nilaksh Bansal 14-IT-09 05420803109

What is Solr
Solr is pronounced as Solar. It stands for Searching on Lucene . Web-based Indexing & Searching Server By default, comes bundled with Jetty server Can also be deployed in any other servlet container like Tomcat, Resin etc.

Advantages of Solr
Solr can replicate index on multiple servers. Uses REST based web-services for indexing and searching Indexing and search can be done simultaneously. Supports faceted searching. Supports result clustering. Supports Hit highlighting Supports Multiple output formats (XML/XSLT and JSON).

Deploying Solr
Following are the steps for deploying Solr in Jetty:

Download Solr and install it. Root directory of Solr [eg: D:\tools\solr] is referred as SOLR_HOME.
Start Solr services. To start the service, execute start.jar present in SOLR_HOME/example/. java jar start.jar

Default port for jetty is 8983.Once the service is started, type in URL
http://localhost:8983/solr Solr admin screen appears.

Important Config Files


solrconfig.xml - Describes the configuration of the server Response handler Faceted Search Clustering of result Query Parser Master Slave replication

schema.xml - Describes the data type Field type Analyzer and Tokenizer used on fields Copy fields Default Field

Solr Indexing

Solr indexing is done using Solr language clients.


Available for Java, Ruby, C etc.

Using Java Language Client solrj:


There are around 7 to 8 jars which need to copied into lib of eclipse project Modify schema.xml for the necessary fields along with Analyzer
<fields> <field name="employeeid" type="integer" indexed="true" stored="true"/> </fields>

In Java project, use solrj API for indexing Initialize SolrServer. Create document Insert fields into document. Add the documents to server. Commit the server.

Run the application.

Solr Indexing - contd


Initialize SolrServer SolrServer _server = new CommonsHttpSolrServer ("http://localhost:8983/solr");

Insert fields into document SolrInputDocument doc1 = new SolrInputDocument(); doc1.addField ("employeeid", "1234");
Add the documents to server _server. add (doc1); Server commit _server. commit (); Executing the application Before running the application, ensure the solar service has started. Execute the application. View in Solr by running Queries http://localhost:8983/solr Output, by default, is visible in XML format.

Solr Search

One option to search over the solr index is using SolrJ. For this, the user needs to define the server, create query object, and send the query to the server to fetch response. SolrServer _server = new CommonsHttpSolrServer ("http://localhost:8983/solr"); SolrQuery solrquery = new SolrQuery (); solrquery.setQuery (<enter query here>); QueryResponse rsp = _server.query (solrquery); In Solr, the search queries are processed by the appropriate SolrRequestHandler. Range, Prefix, Boolean, Wildcard queries are allowed in Solr.

Solr Nut and Bolts


Solr is built on top of Lucene Solr uses different handler to perform different functionality
Data Import Handler Request Handler Response Handler Faceted Search Handler

Why Solr
Replication of Index Scalable and Fault Tolerant (Depending upon the underlying infrastructure) Built in Faceted Search Capabaility

Updation of indexes Distributed Search Load Balancing

SCREENSHOTS

Resources
http://lucene.apache.org http://lucene.apache.org/solr
http://minion.dev.java.net/

Thank You

You might also like