Nhibernate用Lucene.Net搜索历史数据

时间:2011-03-11 01:40:18

标签: nhibernate lucene.net

当我在Nhinbernate中搜索SQL全文索引解决方案时,我遇到了Lucene.Net解决方案,我在http://www.d80.co.uk/post/2011/03/04/Nhibernate-Search-Tutorial-with-LuceneNet-and-NHibernate-30.aspx找到了优秀的文章。

现在我有另一个问题,我有一个现有的应用程序,我正在迁移它以使用Nhibernate。为了使搜索功能正常工作,我假设需要首先将所有现有数据预加载到Lucene索引中。

由于Nhibernate.search是Lucene.Net的一个环节,我认为它必须有自己的文档/字段约定。所以任何人都有一些最佳实践或代码示例如何将数据库中的数据预加载到Lucene索引中?

由于 哈迪

1 个答案:

答案 0 :(得分:1)

这真的是一次性工作......一旦你设置了所有内容,就会为每个映射和索引类运行一个查询,它将获取所有结果......

var allFoo = NHibernateSession.CreateCriteria(typeof(Foo)).List<Foo>();
foreach (var foo in allFoo)
    NHibernateFullTextSession.Index(foo);

最后你可以运行

SearchFactoryImpl sfi = SearchFactoryImpl
                           .GetSearchFactory(new Configuration().Configure());
sfi.Optimize(typeof(Foo));