Integrating Nhibernate.Search with Nhibernate 2

后端 未结 1 1183
鱼传尺愫
鱼传尺愫 2021-02-11 01:19

I have just spent all day attempting to get NHibernate.Search working alongside NHibernate 2.0 and am sorry to say that I have still not managed it. I ran into the problem poste

1条回答
  •  隐瞒了意图╮
    2021-02-11 02:10

    In order to setup 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 changed in order to include the following:

    
    
        
            
    NHibernate.Search.Store.FSDirectoryProvider, NHibernate.Search PATH TO LUCENE.NET STORE event ...

    And finally: when you create an ISession instance, remember to use this code in order to get an IFullTextSession instead.

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

    This should work with Lucene 2.0 and NHibernate 2.0.

    0 讨论(0)
提交回复
热议问题