Saturday, 26 April 2014

Solr configuration with SQL Server

Required software.


apache-tomcat-7.0.53.exe for windows.
solr 4.7.1

Download both Zip


Steps To Configure Solr Server on Windows.


* Configure Apache-tomcat.


1) Install apache-tomcat-7.0.53.exe.2) Select default port fpr appache-tomcat 8080 or 8983.3) After installation goto -> Start -> Configure Apache -> Start service.

* Configure solr server.


1) Stop Apache Service.

2) download and extract solr-4.7.1.zip.

3) goto -> solr-4.7.1 -> dist folder.

4) Copy solr-4.7.1.war to C:\Programfiles\ApacheTomact\webapps.

5) Rename solr-4.7.1.war to solr.war.

6) goto -> solr-4.7.1 -> example -> lib -> ext.

7) Copy all files to C:\Programfiles\ApacheTomact\lib.

8) Download sqljdbc4.jar and paste it to C:\Programfiles\ApacheTomact\lib.(This jar file used to connect jdbc to Microsoft Sql Server.)

9) Create Solr folder in C: drive.

10) goto -> solr-4.7.1 -> example -> solr

11) Copy all files and paste them to C:\Solr.

12) goto -> Start -> Configure Apache.

13) Select Java tab and add -Dsolr.solr.home=C:\Solr in Java Options.

14) Start service.

15) goto -> http://localhost:8080{port}/solr.


All Set!!!


* Adding core to solr server.


1) Enter proper name to solr.

2) Enter path of instance directory.

3) Enter path of data directory.

4) Instance directory should be present on machine before creating core.

5) Instance directroy should contain follwing files.

-> conf folder -> conf -> solrconfig.xml and schema.xml and dataconfig.xml(optional). -> bin folder -> data folder -> lib folder -> lib -> copy solr-dataimporthandler-{version}.jar and solr-dataimporthandler-extras-{version}.jar from solr-4.7.1 -> dist folder 

6) Instance directory should contain folder data directory (data folder).

7) Click add.


* Steps to configure Data import for core


* Steps to configure solr core to pull data from microsoft sql server.


1) Create dataconfig.xml in core conf folder.

2) Add follwing content to dataconfig.xml. 

<dataConfig>
 <dataSource type="JdbcDataSource" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://localhost;databaseName=dbname" user="dbusername" password="dbpassword"/>  <document name="productreviews">    <entity name="review" query="SELECT column1 ,Column2 from Table">      <field column="column1" name="id"/>      <field column="Column2" name="searchtext"/>    </entity>  </document></dataConfig>


3) save dataconfig.xml.

4) Open schema.xml.

5) Add fields specified in dataconfig file.

6) Specify Uniqekey and defaultsearchtext.

<uniqueKey>id</uniqueKey>   <defaultSearchField>text</defaultSearchField>

7) Enter copy field.

<copyField source="searchtext" dest="text"/>

8) Open solrconfig.xml.

9) Add libraries.

<lib dir="./{core folder}/lib/" regex=".*\.jar" /><lib dir="./{core folder}/lib/" regex="apache-solr-dataimporthandler-\d.*\.jar" /><lib dir="./{core folder}/lib/" regex="sqljdbc4.jar" />

10) change <dataDir> to ${solr.data.dir:./{core folder}/data}.

11) Save . Done.

12) Now goto -> browser paste http://localhost:8983{port}/solr/{core name}/dataimport?command=full-import

Done.