开发者

Nhibernate search with Lucene.Net, historical data

开发者 https://www.devze.com 2023-02-16 07:39 出处:网络
When I was searching for SQL full text index solution in Nhinbernate, I came across Lucene.Net solution, and I found and excellent article at http://www.d80.co.uk/post/2011/03/04/Nhibernate-Search-Tut

When I was searching for SQL full text index solution in Nhinbernate, I came across Lucene.Net solution, and I found and excellent article at http://www.d80.co.uk/post/2011/03/04/Nhibernate-Search-Tutorial-with-LuceneNet-and-NHibernate-30.aspx.

Now I have another question that, I have one existing application and I am migrating it to use Nhibernate. In order to make search function to work properly, I assume need to preload all existing data into Lucene index first.

Since Nhibernate.search is a wrap around Lucene.Net, I think it must have its own document/field convention. So anybody has some best practice or code sample how shall I preload dat开发者_C百科a in database into Lucene index?

Thanks Hardy


well this is a one-time job really... once you've setup everything run a query for each mapped and indexed class that will fetch all of the results...

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

in the end you can run

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

精彩评论

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