将Nhibernate.Search与Nhibernate 2集成 [英] Integrating Nhibernate.Search with Nhibernate 2

查看:94
本文介绍了将Nhibernate.Search与Nhibernate 2集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了整整一天的时间尝试获取NHibernate.Search与NHibernate 2.0一起工作,很遗憾地说我仍然没有对其进行管理.我遇到了此处发布的问题,并下载了该帖子链接的dll,但是该示例使用搜索Interceptor而不是EventListeners,我认为这是更新的工作方式.似乎几乎没有可用的信息,我所能找到的信息很难理解并且与其他信息相矛盾.

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.

在这一点上,我对整个过程感到非常沮丧,并且正在认真考虑只编写我自己的Nhibernate和Lucene(或者可能是另一个索引库)的集成.目前,NHibernate.Search似乎已经足够成熟,可以考虑使用它了,我将更愿意维护自己的简化库.

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.

我想知道的是,是否存在使用NHibernate的明确方法.使用NHibernate 2进行搜索以及在生产环境中使用它是否可行.

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.

推荐答案

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

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();

您的web.config/app.config文件必须更改,以包括以下内容:

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>

    ...

最后:创建ISession实例时,请记住使用此代码来获取IFullTextSession.

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());

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

This should work with Lucene 2.0 and NHibernate 2.0.

这篇关于将Nhibernate.Search与Nhibernate 2集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆