Indexing Documents in SOLR

in utopian-io •  7 years ago  (edited)

Solr is an Open-Source Search Platform built on Lucene which makes searching fairly easy. In this tutorial we will see how we can Index documents in SOLR. Indexing means adding content to the SOLR index which can be easily searchable.

image.png

PC : Wikipedia

The advantage of using SOLR is that, it can accept the data from any sources be it JSON file, XML or even database. Whatever be the source of data, one thing is common among them is how to fed the data to the SOLR which is nothing but as a document. A document contains multiple fields having name and content.

Since I mainly work with Rational Database, I use DataImportHandler for getting the data out of the database. The main steps to follow while indexing the documents are

  1. Read the data
  2. Create SOLR documents
  3. Differentiate between Full and Partial Update (Inserting and Updating).

DataImportHandler

Now the next step is to configure the DataImportHandler in the SOLRConfig.xml file and you need to provide the location of data-config file which has the code to fetch the data, read the data and process the data to create SOLR document.

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
  <lst name="defaults">
    <str name="config">pathtoconfigfile.xml</str>
  </lst>
</requestHandler>

The Sample Data-Config File looks like below :

<dataConfig>
    <dataSource driver="org.hsqldb.jdbcDriver" url="URL of Data Source" user="sa" />
    <document>
        <entity>
             //the entity which you would like to import
        </entity>
    </document>
</dataConfig>

The commands used by DataImportHandler are :

  1. Abort - To abort indexing the documents.
  2. Full-Import - It will import all the documents from the database. Note that querying is not blocked while full-import is going on. Full import usually takes some time depending on the number of documents.
  3. Delta-Import - It imports only the new documents or any changes happened to the previous documents.
  4. Status - Shows the number of documents created, updated or deleted.



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Qurator
Your Quality Content Curator
This post has been upvoted and given the stamp of authenticity by @qurator. To join the quality content creators and receive daily upvotes click here for more info.

Qurator's exclusive support bot is now live. For more info click HERE or send some SBD and your link to @qustodian to get even more support.

Found your post interesting to read. I can't wait to see your post soon. Good Luck with the upcoming update.This article is really very interesting and effective. @codingdefined

How did you become a moderator for Utopian? I'm interested but don't know how to start.

You can contact on Utopian Discord, if there is a slot empty you can be the one.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @codingdefined I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x