开发者

Nhibernate Search post-update listener

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="hiberna开发者_StackOverflowte.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() });


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


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" /> 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜