我已经使用我的nhibernate / ActiveRecord项目整合了nHibernate搜索。
我试图让我的更新后监听器正常工作,但似乎每次更新我的一个用[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() });
答案 0 :(得分:1)
原来我的应用程序抛出异常,但除非我正在调试,否则没有被提取。
答案 1 :(得分:0)
如果通过配置添加侦听器,则无需以编程方式添加侦听器。
您是否尝试从配置中删除以下行:
<add key="hibernate.search.indexing_strategy" value="event" />
<add key="hibernate.search.reader.strategy" value="shared" />