Using MongoDB as a data source to build the SOLR search engine Create synchronous Index implementation

Source: Internet
Author: User
Tags solr

The following program uses SOLR as the search module, and the first step in searching for the key is to create an index. The generation of indexes we generally use the data in the database as the data source. But the data in the database is constantly changing, the data of the database changes how to synchronize index to SOLR. The following procedure is to solve this problem. The MONGO database has been changed by using the Open source project Mongo-connector on GitHub as a tool that can detect changes in the database at all times to enable synchronization of indexes with SOLR.


One: Configure SOLR


The SOLR version used is SOLR 4.5.1

1) Unzip the zip
2) Copy the Solr.war under the D:/solr-4.5.1/example/webapps to the Tomcat–>weapps
3) New Folder D:/sorl_home, copy the D:/SOLR-4.5.1/EXAMPLE/SOLR directory to D:/sorl_home
4) When Tomcat is started, Tomcat will unzip the Solr.war to generate a SOLR folder, stop Tomcat, and delete Solr.war.

After running Tomcat access: HTTP://LOCALHOST:8080/SOLR

5) Modify the ID in the Schema.xml configuration file to _id:


Two: Configure MongoDB


1) Open Oplog, also need to start a replica set in MONGO

My mongo_home is D:\mongodb.

The directory tree is as follows:

-rs (d)

|----db (d) directory where the MONGO data file file is stored

|----rs1 (d) directory where rs1 instance data files are stored

|----RS2 (d) directory where RS2 instance data files are stored

|----The directory where log (d) log files are stored

|----rs1.log (f) log file for the Rs1 instance

|----rs2.log (f) log file for the RS2 instance

|----The startup script for the Mongod-rs1.bat rs1 instance

|----The startup script for the Mongod-rs2.bat rs2 instance


Mongod-rs1.bat content is as follows:

D:\MongoDB\mongod--port 27001--oplogsize--dbpath db\rs1--logpath log\rs1.log--replset rs/127.0.0.1:27002--journ Al
Pause

Mongod-rs2.bat content is as follows:

D:\MongoDB\mongod--port 27002--oplogsize--dbpath db\rs2--logpath log\rs2.log--replset rs/127.0.0.1:27001--journ Al
Pause

2) Execute two scripts and launch two Mongod instances

3) But at this point they have not formed a replica set, but also need to configure, open MONGO, connected to localhost:27001, that is, the instance rs1


After the configuration is complete:
View Rs.initiate (config) rs.status ()

Three: Start Mongo-connector

GitHub Address (Https://github.com/10gen-labs/mongo-connector)

D:\ Project Information \dht\mongo-connector-master\mongo-connector-master\mongo_connector>py
Thon Connector.py-m localhost:27001-t Http://localhost:8080/solr/collection1-
o oplog_progress.txt-n test.foo-u _id-d./doc_managers/solr_doc_manager.py

Python connector.py-m localhost:27001-t http://localhost:8080/solr/collection1-o oplog_progress.txt-n Torrentinfo-db.torrent_info-u _id-d./doc_managers/solr_doc_manager.py

Note where the-n parameter is the name of the database table to be indexed

Four: Testing

Add a record in MONGO:

Db.foo.insert ({title: ' Hello World '})

Output in Mongo-connector:

2014-07-26 23:18:42,881-info-finished ' http://localhost:8080/solr/collection
1/update/?commit=false ' (POST) with the body ' u ' <add><do ' in 295.228 seconds.

Query in SOLR:


Using MongoDB as a data source to build the SOLR search engine Create synchronous Index implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.