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 ?
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
当需要在Hibernate映射数据库上实现基于Lucene的搜索引擎时,您肯定想签出Hibernate Search 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.