Nhibernate Search 更新后侦听器
我已经将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,我的应用程序抛出了异常,但除非我正在调试,否则不会被捕获。
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 :