流利的nhibernate + nhibernate.serach + lucene.net [英] Fluent nhibernate + nhibernate.serach + lucene.net

查看:166
本文介绍了流利的nhibernate + nhibernate.serach + lucene.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉我如何使用nhibernate serach和lucene流利的nhibernate。我有我的应用程序写流利nhibernate,但现在我需要全文serach,但不知道如何implmenet nhibernate与lucene的流利nhibernate搜索。



我发现这个,但它是不是很多,不知道如何使用它:
流利的NHibernate + Lucene搜索(NHibernate.Search)



thx in advanced

解决方案

Lucene.net是一个独立的搜索和目录工具。据我所知,它不能通过映射与nhibernate集成。
您应该自己实现向lucene索引添加数据。 Lucene允许将自定义字段添加到索引中,以便您可以将记录的数据库ID与索引文本一起添加。



例如,如果要添加带ID的文本对象你可以这样做:

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



$ b

维护索引的策略取决于您的应用程序。每次向数据库提交数据时,您都可以将数据添加到索引中,或者您可以逐渐增加数据量 - 每天一次(您必须存储关于每当记录被索引或不在数据库表中时的信息)。 b
$ b

如果创建了索引,您可以使用IndexSearcher对象来搜索索引,然后将搜索结果与使用ID的NHibernate对象进行组合。


can someone tell me how to use nhibernate serach and lucene with fluent nhibernate. I have my application writen 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.

这篇关于流利的nhibernate + nhibernate.serach + lucene.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆