0
votes

I have built a java based web application using Springs-Hibernate Framework and MySQL Database. I want to integrate search functionality in my application using lucene. Since i am new to lucene, can anyone help me with the steps to index data from my database and implement search functionality ?

2

2 Answers

0
votes

You can begin by downloading Lucene 4.x and writing code to fetch each row from the database.

Then use the example given in this documentation to index it: http://lucene.apache.org/core/4_4_0/core/overview-summary.html#overview_description

For your use case this part of the example needs to loop over all your rows to index it.

Document doc = new Document();
String text = "This is the text to be indexed.";
doc.add(new Field("fieldname", text, TextField.TYPE_STORED));
iwriter.addDocument(doc);

Although I would suggest use Solr (http://www.apache.org/dyn/closer.cgi/lucene/solr/4.4.0) which is a search application built on lucene for this example. It provides a extensive ways to index documents from relational databases. http://wiki.apache.org/solr/DataImportHandler

0
votes

When needing to implement a Lucene based search engine on a Hibernate mapped database, you definitely want to check out Hibernate Search.