Nhibernate Search 更新后侦听器

发布于 2024-10-23 21:08:46 字数 2815 浏览 4 评论 0原文

我已经将 nHibernate 搜索与我的 nhibernate/ActiveRecord 项目集成在一起。

我试图让我的更新后侦听器正常工作,但似乎每次我更新用 [Indexed] 属性装饰的对象之一时,它都会导致 nhibernate.search 创建一个新的 IndexReader (Workspace.cs GetIndexReader方法)大约需要30秒!

知道为什么 nhibernate.search 这样做吗?

这是我的配置

<configSections>
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
    </configSections>
  <activerecord isWeb="true">
    <config>
      <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
      <add key="dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
      <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="connection.connection_string" value="Data Source=***;user id=****;password=****;Initial Catalog=*****" />
      <add key="hibernate.search.default.directory_provider" value="NHibernate.Search.Store.FSDirectoryProvider, NHibernate.Search" /> 
      <add key="hibernate.search.default.indexBase" value="C:\LuceneIndex" />
      <add key="hibernate.search.analyzer" value="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
      <add key="hibernate.search.indexing_strategy" value="event" />
      <add key="hibernate.search.reader.strategy" value="shared" />  
    </config>
  </activerecord>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu </property>
      <event type="delete">
        <listener class="SoftDeleteListener, Mydll"/>
      </event>
      <event type="post-update">
        <listener class="NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search" />
      </event>
      <event type="post-insert"> 
        <listener class="NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search" />
      </event>
      <event type="post-delete">
        <listener class="NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search" />
      </event>
    </session-factory>
  </hibernate-configuration>

,我正在以编程方式添加我的事件侦听器(目前仅更新后)

NHibernate.Cfg.Configuration configuration = ActiveRecordMediator.GetSessionFactoryHolder().GetConfiguration(typeof(ActiveRecordBase));
configuration.SetListeners(ListenerType.PostUpdate, new IPostUpdateEventListener[] { new FullTextIndexEventListener() });

I have intergrated nHibernate search, with my nhibernate/ActiveRecord project.

I am trying to get my post-update listener to work correctly but it seems that every time I update one of my objects which is decorated with the [Indexed] attribute, it causes nhibernate.search to create a new IndexReader (Workspace.cs GetIndexReader method) which takes about 30 seconds!

Any idea why nhibernate.search is doing this?

Heres my config

<configSections>
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
    </configSections>
  <activerecord isWeb="true">
    <config>
      <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
      <add key="dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
      <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="connection.connection_string" value="Data Source=***;user id=****;password=****;Initial Catalog=*****" />
      <add key="hibernate.search.default.directory_provider" value="NHibernate.Search.Store.FSDirectoryProvider, NHibernate.Search" /> 
      <add key="hibernate.search.default.indexBase" value="C:\LuceneIndex" />
      <add key="hibernate.search.analyzer" value="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
      <add key="hibernate.search.indexing_strategy" value="event" />
      <add key="hibernate.search.reader.strategy" value="shared" />  
    </config>
  </activerecord>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu </property>
      <event type="delete">
        <listener class="SoftDeleteListener, Mydll"/>
      </event>
      <event type="post-update">
        <listener class="NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search" />
      </event>
      <event type="post-insert"> 
        <listener class="NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search" />
      </event>
      <event type="post-delete">
        <listener class="NHibernate.Search.Event.FullTextIndexEventListener, NHibernate.Search" />
      </event>
    </session-factory>
  </hibernate-configuration>

I am programitcally adding my event listener (post-update only for now)

NHibernate.Cfg.Configuration configuration = ActiveRecordMediator.GetSessionFactoryHolder().GetConfiguration(typeof(ActiveRecordBase));
configuration.SetListeners(ListenerType.PostUpdate, new IPostUpdateEventListener[] { new FullTextIndexEventListener() });

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

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

发布评论

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

评论(2

欢烬 2024-10-30 21:08:46

事实证明,我的应用程序抛出了异常,但除非我正在调试,否则不会被捕获。

Turns out my application was throwing an exception but wasn't picked up unless I was debugging.

灰色世界里的红玫瑰 2024-10-30 21:08:46

如果通过配置添加侦听器,则无需以编程方式添加侦听器。

您是否尝试过从配置中删除以下行:

<add key="hibernate.search.indexing_strategy" value="event" />
<add key="hibernate.search.reader.strategy" value="shared" /> 

You don't need to add the listeners programmaticaly if you add them via configuration.

Have you tried removing the following lines from the configuration :

<add key="hibernate.search.indexing_strategy" value="event" />
<add key="hibernate.search.reader.strategy" value="shared" /> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文