开发者

Fluent nhibernate + nhibernate.serach + lucene.net

can someone tell me how to use nhibernate serach and lucene with fluent nhibernate. I have my application writen开发者_StackOverflow中文版 with fluent nhibernate but now i need full text serach but do not know how to implmenet nhibernate search with lucene to fluent nhibernate.

i found this but it is not much and do not know how to use it: Fluent NHibernate + Lucene Search (NHibernate.Search)

thx in advanced


Lucene.net is a self-contained search and directory utility. As far as I know it cannot be integrated with nhibernate by mappings only. You should implement adding data to lucene index by yourself. Lucene allows to add custom fields to index so you can add your database id's of the records together with indexed texts.

For example, if you want to add text object with id to lucene index you can do it like that:

public void AddRecordToIndex(string text, int id)
{
    IndexWriter writer = new IndexWriter("c:\\index\\my", new StandardAnalyzer(), true);
    Document doc = new Document();
    doc.add(Field.Text("contents", text));
    doc.add(Field.Keyword("id", id.ToStrirng()));
    writer.addDocument(doc);
}

The strategy of maintaining the index depends of your application. You can add data to index each time they are commited to database or you can do it incrementally - once a day (you have to store the information about whenever the record is indexed or not in your database table then).

If the index is created you can search it with IndexSearcher object, and then combine the search results with you NHibernate objects using the id's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜