将 Nhibernate.Search 与 Nhibernate 2 集成

发布于 2024-07-17 23:21:16 字数 480 浏览 5 评论 0原文

我刚刚花了一整天的时间尝试让 NHibernate.Search 与 NHibernate 2.0 一起工作,很遗憾我还没有成功。 我遇到了此处发布的问题并下载了该帖子链接的 dll,但是示例使用搜索拦截器而不是事件监听器,我相信这是更新的处理方式。 可用的信息似乎很少,而且我能找到的信息很难理解并且与其他信息相矛盾。

此时我对整个事情感到非常沮丧,并且正在认真考虑编写自己的 Nhibernate 和 Lucene(或者可能是另一个索引库)集成。 目前看来 NHibernate.Search 还不够成熟,不足以让我考虑使用它,我会更舒服地维护自己的更简化的库。

我想知道是否有一种将 NHibernate.Search 与 NHibernate 2 一起使用的明确方法,以及在生产环境中使用它是否可行。

I have just spent all day attempting to get NHibernate.Search working alongside NHibernate 2.0 and am sorry to say that I have still not managed it. I ran into the problem posted here and downloaded the dll linked by that post, however the example uses a search Interceptor rather than EventListeners, which I believe to be the newer way of doing things. There seems to be very little information available and what I can find is difficult to understand and contradicts other pieces of information.

At this point I am pretty frustrated with the whole thing and am seriously considering just writing my own integration of Nhibernate and Lucene (or perhaps another indexing library). At the moment it seems that NHibernate.Search is nowehere near mature enough for me to consider using it, I would be far more comfortable maintaining my own rather more simplified library.

What I would like to know is if there is a definitive way of using NHibernate.Search with NHibernate 2 and whether it is feasible to use this in a production environment.

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

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

发布评论

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

评论(1

似最初 2024-07-24 23:21:16

为了设置 EventListeners,您需要在初始化 NHibernate 时添加以下代码:

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
//Load configuration

//Add NHibernate.Search listeners
cfg.SetListener(NHibernate.Event.ListenerType.PostUpdate, new FullTextIndexEventListener());
cfg.SetListener(NHibernate.Event.ListenerType.PostInsert, new FullTextIndexEventListener());
cfg.SetListener(NHibernate.Event.ListenerType.PostDelete, new FullTextIndexEventListener());

var factory = cfg.BuildSessionFactory();

必须更改 web.config/app.config 文件以包含以下内容:

<configuration>

    <configSections>
        <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false"/>
        <section name="nhs-configuration" type="NHibernate.Search.Cfg.ConfigurationSectionHandler, NHibernate.Search" requirePermission="false"/>
    </configSections>

    <!-- NHibernate.Search -->
    <nhs-configuration xmlns='urn:nhs-configuration-1.0'>
        <search-factory>
            <property name='hibernate.search.default.directory_provider'>NHibernate.Search.Store.FSDirectoryProvider, NHibernate.Search</property>


            <property name='hibernate.search.default.indexBase'>PATH TO LUCENE.NET STORE</property>

            <property name='hibernate.search.indexing_strategy'>event</property>
        </search-factory>
    </nhs-configuration>

    <appSettings>
        <add key="Lucene.Net.lockdir" value="SAME PATH AS ABOVE" />
    </appSettings>

    ...

最后:当您创建 ISession 实例时,请记住使用此代码为了获得 IFullTextSession 。

IFullTextSession session = Search.CreateFullTextSession(factory.OpenSession());

这应该适用于 Lucene 2.0 和 NHibernate 2.0。

In order to setup EventListeners, you need to add this code when initializing NHibernate:

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
//Load configuration

//Add NHibernate.Search listeners
cfg.SetListener(NHibernate.Event.ListenerType.PostUpdate, new FullTextIndexEventListener());
cfg.SetListener(NHibernate.Event.ListenerType.PostInsert, new FullTextIndexEventListener());
cfg.SetListener(NHibernate.Event.ListenerType.PostDelete, new FullTextIndexEventListener());

var factory = cfg.BuildSessionFactory();

Your web.config/app.config file must be changed in order to include the following:

<configuration>

    <configSections>
        <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false"/>
        <section name="nhs-configuration" type="NHibernate.Search.Cfg.ConfigurationSectionHandler, NHibernate.Search" requirePermission="false"/>
    </configSections>

    <!-- NHibernate.Search -->
    <nhs-configuration xmlns='urn:nhs-configuration-1.0'>
        <search-factory>
            <property name='hibernate.search.default.directory_provider'>NHibernate.Search.Store.FSDirectoryProvider, NHibernate.Search</property>


            <property name='hibernate.search.default.indexBase'>PATH TO LUCENE.NET STORE</property>

            <property name='hibernate.search.indexing_strategy'>event</property>
        </search-factory>
    </nhs-configuration>

    <appSettings>
        <add key="Lucene.Net.lockdir" value="SAME PATH AS ABOVE" />
    </appSettings>

    ...

And finally: when you create an ISession instance, remember to use this code in order to get an IFullTextSession instead.

IFullTextSession session = Search.CreateFullTextSession(factory.OpenSession());

This should work with Lucene 2.0 and NHibernate 2.0.

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