简体   繁体   English

使用Lucene的搜索功能

[英]Search Functionality using Lucene

I have built a java based web application using Springs-Hibernate Framework and MySQL Database. 我已经使用Springs-Hibernate Framework和MySQL Database构建了一个基于Java的Web应用程序。 I want to integrate search functionality in my application using lucene. 我想使用Lucene将搜索功能集成到我的应用程序中。 Since i am new to lucene, can anyone help me with the steps to index data from my database and implement search functionality ? 既然我是Lucene的新手,那么有人可以帮助我为数据库中的数据建立索引并实现搜索功能的步骤吗?

You can begin by downloading Lucene 4.x and writing code to fetch each row from the database. 您可以先下载Lucene 4.x,然后编写代码以从数据库中获取每一行。

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 然后使用本文档中给出的示例对其进行索引: 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. 尽管我建议使用Solr( http://www.apache.org/dyn/closer.cgi/lucene/solr/4.4.0 ),但此示例是基于Lucene构建的搜索应用程序。 It provides a extensive ways to index documents from relational databases. 它提供了广泛的方法来索引关系数据库中的文档。 http://wiki.apache.org/solr/DataImportHandler http://wiki.apache.org/solr/DataImportHandler

当需要在Hibernate映射数据库上实现基于Lucene的搜索引擎时,您肯定想签出Hibernate Search

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM