Thursday, 26 May 2016

Install solr in 2 minutes linux

Solr implementation commands:
             sudo apt-get update
            java -version
            sudo apt-get install default-jre
            sudo apt-get install default-jdk
            sudo apt-get install openjdk-7-jre
            sudo apt-get install openjdk-7-jdk

solr package :

wget http://archive.apache.org/dist/lucene/solr/4.9.0/solr-4.9.0.tgz

The MySQL jdbc driver

With that out of the way, let’s get Solr up and running and ready for database indexing:
  1. Download Solr and extract it to a directory of your choice.
  2. Open solr-4.9.0/example/solr/collection1/conf/solrconfig.xml in a text editor and add the following within the config tags:
    <lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
    <lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />

    <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
        <lst name="defaults">
              <str name="config">db-data-config.xml</str>
          </lst>
    </requestHandler>
  3. In the same directory, open schema.xml and add this this line 
    <dynamicField name="*_name" type="text_general" multiValued="false" indexed="true" stored="true" />
  4. Create a lib subdir in solr-4.9.0/solr/collection1/ and extract the MySQL jdbc driver jar into it. It’s the file called mysql-connector-java-{version}-bin.jar
  5. To start Solr, open a terminal and navigate to the example subdir in your extracted Solr directory and run java -jar start.jar

Indexing our database

In your Solr conf directory, which contains the schema.xml and solrconfig.xml we previously modified, create a new file called db-data-config.xml.

<dataConfig>
  <dataSource type="JdbcDataSource"
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/employees"
            user="user"
            password="password" />
  <document>
    <entity name="id" query="select emp_no as 'id', first_name, last_name from employees limit 1000;" />
  </document>
</dataConfig>

For those of you not using Chrome, here are the commands you will need:

Clear index: http://localhost:8983/solr/update?stream.body=<delete><query>*:*</query></delete>&commit=true
Retrieve all: http://localhost:8983/solr/select?q=*:*&omitHeader=true
Index db: http://localhost:8983/solr/collection1/dataimport?command=full-import
Reload core: http://localhost:8983/solr/admin/cores?action=RELOAD&core=collection1
Georgi query: http://localhost:8983/solr/select?q=georgi&wt=json&qf=first_name%20last_name&defType=edismax

No comments:

Post a Comment