Mar
Solr with Apache Tomcat
About Solr
Solr is an open source enterprise search server based on the Lucene Java search library, with XML/HTTP and JSON APIs, hit highlighting, faceted search, caching, replication, a web administration interface and many more features. It runs in a Java servlet container such as Tomcat.
Requirements
To run Solr, Java 1.5 or more is required. Also Firefox is the preferred browser to view the admin pages and test the example before integrating the search in the website.
Configure Solr for Tomcat
By default, Solr comes configured for Jetty server. To be practical, Solr can run in any Java Servlet Container. This document has been written to configure Solr for Tomcat. To do so, follow these steps:
1. Download the latest version of Tomcat and install it. Check if Tomcat is installed correctly by going to http://localhost:8080/.[[BR]] Note: We are installed tomcat 6 in our production and live server. Better you installed the same in your local machine.
2. Open $TOMCAT_HOME/conf/tomcat-users.xml and add the following piece of code:
3. If we have to query Solr using international characters (>127) using HTTP-GET, we must configure Tomcat to conform to the URI standard by accepting percent-encoded UTF-8.
4. Edit $TOMCAT_HOME/conf/server.xml and add the following attribute to the correct Connector element: URIEncoding=”UTF-8″.
…
This is only an issue when sending non-ascii characters in a query request. No configuration is needed for Solr/Tomcat to return non-ascii chars in a response, or accept non-ascii chars in an HTTP-POST body.
5.Download and unzip the Solr distribution zip file. Make a directory called solr where you intend the application server to function, say c:Solr\web\solr\.
Note: We are using solr 1.4 on our staging and production servers, better you installed the same in local machine.
6.Copy the contents of the $SOLR_HOME\example\solr directory to c:Solr\web\solr\.[[BR]] 7.Stop the Tomcat service.
8.Copy the *solr*.war file from $SOLR_HOME\dist\ to the Tomcat webapps directory c:\tomcat\webapps\.
9.Rename the *solr*.war file solr.war.
10.Configure Tomcat to start with the following Java option: -Dsolr.solr.home=c:Solr\web\solr.[[BR]] Note: This is not required in linux machine 11.Start the Tomcat service and go to the solr admin page to verify that the installation is working. It will be at http://localhost:8080/solr/admin.[[BR]]
Configure JDBC dataSource on Tomcat
Before starting any further, we need to add the mysql jdbc driver file into $TOMCAT_HOME/lib directory
Now follow these steps:
1.Navigate to $TOMCAT_HOME\conf\Catalina\localhost to create a file named solr.xml and add the following lines in it.
Index the Data for Searching with Solr
Now, we need to create few files and modify some other files to get our data indexed. 1.Navigate to c:Solr\web\solr\ and create a file by name data-import.xml. And add:
driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/$DB_NAME" user="$USERNAME" password="$PASSWORD"/> query="select id,catid,sectionid,title ,created,created_by,state,CONCAT(introtext, fulltext) AS text, alias as articlealias,hits from jos_content;" deltaImportQuery="select id,catid,sectionid,title ,created,created_by,state,CONCAT(introtext, fulltext) AS text, alias as articlealias,hits from jos_content where id='${dataimporter.delta.id}'" deltaQuery="select id from jos_content where modified > ‘${dataimporter.last_index_time}’”> query="select alias as catalias,title as cattitle from jos_categories where id='${outer.catid}'"> query="select title as sectitle from jos_sections where id='${outer.sectionid}'"> query="select name as author from jos_users where id='${outer.created_by}'"> In the above code, we are mentioning which tables to index as well as which fields to index along with the dataSource. In the above mentioned example, we are fetching data from four tables by indexing all the fields. We are using delta-import to index the latest/modified records to solr. Please check the delta-import example through below url . http://wiki.apache.org/solr/DataImportHandler 2.Now, we need to map these fields with their data types in schema.xml present in c:Solr\web\solr\conf\. We need to edit the xml file as:
