开发者

How do I build an Index in Nhibernate.Search (Lucene.Net)?

开发者 https://www.devze.com 2023-01-06 09:01 出处:网络
I\'m trying to add a search field to my web site (ASP.NET MVC 2) and was told it\'d be a good idea to use Nhibernate.Search, seeing that I was already using Nhibernate in the rest of the project.

I'm trying to add a search field to my web site (ASP.NET MVC 2) and was told it'd be a good idea to use Nhibernate.Search, seeing that I was already using Nhibernate in the rest of the project.

Anyway, I followed a coulpe tutorials, namely this one, and some questions and answeres on this site, but in the end, it does not build an index, and searches come empty.

I know this question might be a bit vague, but it seems strange that nothing works even after I've done everything I was told.

Well, almost everything. At some point, in one of the tutorials, it tells me to type:

using (IFullTextSession s = Search.CreateFullTextSession(sf.OpenSession(new SearchInterceptor()))) {

        QueryParser qp = new QueryParser("id", new StopAnalyzer());

        IQuery NHQuery = s.CreateFullTextQuery(qp.Parse("Summary:series"), typeof(Book));

        IList result = NHQuery.List();

        Debug.Assert(result.Count == 2);
}

wich does not work because SearchInterceptor does not exist anywhere...

Am I missing something here? Is 开发者_如何学运维there a way to better write the search queries? In which part of my application does it build the index?

Thanks in advance.


I've tried something like:

public bool LuceneIndexAllVideos()
    {
        var s = NHibernate.Search.Search.CreateFullTextSession(Session);

        foreach (Video video in Videos)
        {
            s.Index(video);
        }
        return true;
    }

But is slow, but it seems to work nice... See: https://stackoverflow.com/questions/6989125/lucene-net-nhibernate-updating-lucene-index-from-existing-data

0

精彩评论

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