Nhibernate.Search Integration with Nhibernate 2

I just spent all day trying to get NHibernate.Search working with NHibernate 2.0, and I'm sorry that I still could not handle it. I ran into a problem posted here and downloaded the dll associated with this post, however this example uses the Interceptor search, not EventListeners, which I believe is a newer way of doing things. It seems that there is very little information, and what I can find is difficult to understand and contradict other pieces of information.

At the moment I'm very upset about all this, and seriously consider writing my own integration between Nhibernate and Lucene (or perhaps another indexing library). At the moment, it seems that NHibernate.Search is not mature enough now that I can use it, it would be much more convenient for me to support my more simplified library.

I would like to know if there is a final way to use NHibernate.Search with NHibernate 2 and whether it can be used in a production environment.

+3
source share
1 answer

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

Your web.config / app.config file must be modified 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.

IFullTextSession session = Search.CreateFullTextSession(factory.OpenSession());

Lucene 2.0 NHibernate 2.0.

+7

Source: https://habr.com/ru/post/1706535/


All Articles