views:

2037

answers:

3

I'm using Fluent NHibernate and I would like to implement NHibernate.Search with Lucene but I can't find any examples on how to do that with Fluent NHibernate. It appears there are two steps. (According to Castle)

  1. Set the Hibernate properties in the configuration:

    • hibernate.search.default.directory_provider
    • hibernate.search.default.indexBase
    • hibernate.search.analyzer
  2. Initializing the Event Listeners to index persisted objcts

    • configuration.SetListener(ListenerType.PostUpdate, new FullTextIndexEventListener());
    • configuration.SetListener(ListenerType.PostInsert, new FullTextIndexEventListener());
    • configuration.SetListener(ListenerType.PostDelete, new FullTextIndexEventListener());

I figured out how to add properties to the Fluent NHibernate Source Configuration, but I cannot find where the Event Listeners are setup.

+3  A: 

If you're using the Fluent Configuration API, then you just need to use the ExposeConfiguration method to get at the NHibernate Configuration instance.

Fluently.Configure()
  .Database(...)
  .Mappings(...)
  .ExposeConfiguration(cfg =>
  {
    cfg.SetListener(...);
    cfg.SetListener(...);
  })
  .BuildSessionFactory();
James Gregory
This is correct but when I tried this, I ran into other problems with the Fluent NHibernate and the NHibernate.Search assemblies using two different versions of NHibernate. So, this is correct - but it actually doesn't work. Yet. :)
Ryan Montgomery
@rmontgomery429 It's a solution for OSS, you should checkout from the trunk and build it on your own.
Samnang
A: 

Hi Ryan.

Im having the problems configuring Fluent too and im getting "Not a mapped entity: PDFSearch.Domain.Entity.PDFPage"

My configuration is like this.

           return Fluently.Configure()
          .Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.Is(connStr)).ShowSql()
          )


            .ExposeConfiguration(m =>
                {
                    m.SetListener(NHibernate.Event.ListenerType.PostUpdate, new FullTextIndexEventListener() );
                    m.SetListener(NHibernate.Event.ListenerType.PostInsert, new FullTextIndexEventListener());
                    m.SetListener(NHibernate.Event.ListenerType.PostDelete, new FullTextIndexEventListener());
                    m.SetProperty("hibernate.search.default.directory_provider", typeof(RAMDirectoryProvider).AssemblyQualifiedName);
                    m.SetProperty(NHibernate.Search.Environment.AnalyzerClass, typeof(StopAnalyzer).AssemblyQualifiedName);

                }
            )
            .Mappings(m =>

            m.FluentMappings.AddFromAssemblyOf<PDFMap>())
            .BuildSessionFactory();
Keld jakobsen
+1  A: 

I'm working on a Fluent API for Lucene which removes the need for attributes and integrated nicely with FNH

Its still very pre-alpha, contributions welcome!

Andrew Bullock