如何在 Nhibernate.Search (Lucene.Net) 中构建索引?

发布于 2024-09-08 12:21:06 字数 875 浏览 0 评论 0原文

我正在尝试向我的网站 (ASP.NET MVC 2) 添加一个搜索字段,并被告知使用 Nhibernate.Search 是一个好主意,因为我已经在项目的其余部分中使用了 Nhibernate。

不管怎样,我遵循了 coupe 教程,即 这个,以及这个网站上的一些问答,但最终没有建立索引,搜索结果为空。

我知道这个问题可能有点模糊,但奇怪的是,即使我做了我被告知的所有事情,也没有任何效果。

嗯,几乎一切。在某个教程中,它告诉我输入:

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 不起作用,因为 SearchInterceptor 在任何地方都不存在......

我在这里遗漏了什么吗? 有没有更好的方法来编写搜索查询? 它在我的应用程序的哪一部分构建索引?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱不及久伴 2024-09-15 12:21:06

我尝试过类似的方法:

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

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

但是很慢,但似乎效果很好......
看:
https://stackoverflow.com/questions/6989125/lucene- net-nhibernate-updating-lucene-index-from-existing-data

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文