Showing posts with label Search Engine Indexing. Show all posts
Showing posts with label Search Engine Indexing. Show all posts

Wednesday, December 16, 2015

Solr DataImporter using Mongodb

6:15 PM Posted by Unknown , No comments

1. Get required libraries
Download following .jar files:
- solr-mongo-importer-1.0.0.jar (https://github.com/downloads/james75/SolrMongoImporter/solr-mongo-importer-1.0.0.jar)
- mongo-2.10.1.jar (http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.10.1/mongo-java-driver-2.10.1.jar)
save these files into
solr/contrib/dataimporthandler/lib/
2. Configure solrconfig.xml
<lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-dataimporthandler-.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">  
   <lst name="defaults">
      <str name="config">data-config.xml</str>
   </lst>
</requestHandler>
 3. Configure data-config.xml
 <?xml version="1.0"?>
 <dataConfig>
   <dataSource name="mymongodb" type="MongoDataSource" database="MongodbDatabaseName" />
   <document name="data">
   <!-- if query="" then it imports everything -->
    <entity name="users"
            processor="MongoEntityProcessor"
            query=""
            collection="users" 
            datasource="mymongodb"
            transformer="MongoMapperTransformer"> 
      <field column="id" name="id" mongoField="_id" /> 
      <!--<field column="_id" name="id" />-->

      <entity name="company"
              processor="MongoEntityProcessor"
              query="{'_id':'${users.id}'}"
              collection="company" 
              datasource="mymongodb"
              transformer="MongoMapperTransformer"> 
         <field column="company" name="company" mongoField="company"/> 
      </entity>

      <entity name="biodata"
              processor="MongoEntityProcessor"
              query="{'_id':'${users.id}'}"
              collection="users" 
              datasource="mymongodb"
              transformer="script:biodataTransformer">
      </entity>

    </entity> 
  </document> 
<script><![CDATA[
function biodataTransformer(row){
  if(row.get('biodata') !== null){
    var biodata = row.get('biodata')
    if(biodata.get("age") !== null){
      row.put("biodata_age", biodata.get("age").toString());
    }
    if(biodata.get("height") !== null){
      row.put("biodata_height", biodata.get("height").toString());
    }                
  }                 
  return row; 
}
]]></script>
</dataConfig>
4. Configure schema.xml
Define the fields you want to index in schema.xml
5. Import mongodb data into solr with outer join
Fire up solr and go to dataimport tab and execute data import.

Sunday, November 22, 2015

How to install Solr 5.3.1 on Ubuntu 14.04

7:25 PM Posted by Unknown No comments

Step 1: Installing Java

Solr requires Java, so we will install it if you didn't install it before

First, use apt-get to install python-software-properties:

sudo apt-get install python-software-properties

Install the latest version of Java 8 instead of using the default-jdk or default-jre packages

sudo add-apt-repository ppa:webupd8team/java

You will need to press ENTER to accept adding the repository to your index.

Update the source list and install Java8:
sudo apt-get update 
sudo apt-get install oracle-java8-installer

Step 2: Installing Solr

We will begin by downloading the Sorl distribution
wget http://apache.mirror1.spango.com/lucene/solr/5.3.1/solr-5.3.1.tgz

Extract the service installation file: 

tar xzf solr-5.3.1.tgz solr-5.3.1/bin/install_solr_service.sh --strip-components=2 

Install Solr as a service using the script: 

bash ./install_solr_service.sh solr-5.3.1.tgz

Check if the server is running: 

sudo service solr status

Step 3: Creating a Collection

Solr canhave mutiple collections, so you can create a collection by browser at this address: http://localhost:8983/solr/#/~cores or by command:

sudo su - solr -c "/opt/solr/bin/solr create -c collection_name -n data_driven_schema_configs"
Note: Options of solr service
/etc/init.d/solr {start|stop|restart|status} 
Or
sudo service solr  {start|stop|restart|status}