Hi, I don't use ActiveRecord, but I've had similar issues using NH.Seach with Castle NHibernate integration facility. Here is a blog post: http://gschuager.blogspot.com/2008/04/nhibernatesearch-with.html Maybe it can help you.
On Sep 24, 3:31 pm, burkhard_m <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to implement full-text search functionality with > NHibernate.Search 1.2.1.4000, Lucene.NET 2.0.0.4 and > Castle.ActiveRecord 1.0.3.0. > > The main problem is, that I have to register a SearchInterceptor in > order to hook NHibernate.Search into NHibernate so that it can > automatically maintain the search index. > (Source:http://using.castleproject.org/display/AR/Using+NHibernate.Search+wit... > ) > > Well, most examples based on NHibernate suggest to open a new session > with the SearchInterceptor attached: > > using (ISession session = > Global.SessionFactory.OpenSession(new SearchInterceptor())) > using (IFullTextSession fullTextSession = > Search.CreateFullTextSession(session)) > using (NHibernate.ITransaction tx = > session.BeginTransaction()) > { ... } > > But in ActiveRecord this is different. Using the code above creates a > new session which is not linked to the SessionScope / TransactionScope > of ActiveRecord. So any rollback fails or session timeouts may occur. > Instead I would rather prefer to init the full-text session like this: > > using (var tx = new TransactionScope()) > { > var factory = > ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof(Description)); > var session = tx.GetSession(factory); > IFullTextSession fullTextSession = > NHibernate.Search.Search.CreateFullTextSession(session); > > ... > } > > Unfortunately the code above throws a HibernateException: > "\r\nThe session interceptor was not a SearchInterceptor.\r\nIn order > to use Full Text Query, you must open the session with a > SearchInterceptor. Like this:\r\nsessionFactory.OpenSession(new > SearchInterceptor());\r\n" > > Well, but that's not what I want, because the MSSQL Profiler tells me, > that this call always leads to another db transaction and additional > login. > So I tried to figure out if there is any other solution ... and there > is! NHibernate.Cfg.Configuration offers the SetInterceptor() method. > Afterwards my intialization code looked like this: > > IConfigurationSource source = > ActiveRecordSectionHandler.Instance; > ActiveRecordStarter.Initialize(typeof(Description).Assembly, > source); > > ISessionFactoryHolder holder = > ActiveRecordMediator.GetSessionFactoryHolder(); > NHibernate.Cfg.Configuration configuration = > holder.GetConfiguration(typeof(ActiveRecordBase)); > > configuration.SetInterceptor(new SearchInterceptor()); // <- > adds the interceptor > > SearchFactory.Initialize(configuration, > holder.GetSessionFactory(typeof(Description))); > > But the code above still throws a HibernateException with the same > error message as above. > So how do I hook NHibernate.Search into ActiveRecord & NHibernate > without using OpenSession? > In my humble opinion, I have to access the Interceptor directly > through ActiveRecord. But that didn't work out either, because the > property is readonly. Of course I could use Reflection to access it, > but I don't want to mess around with internal code. > Do you have an idea? > > The activerecord documentation wasn't quite helpful, > too:http://www.castleproject.org/activerecord/documentation/trunk/advance... > > By the way, here are my app settings: > > <activerecord isWeb="false"> > <config> > <add key="hibernate.connection.driver_class" > value="NHibernate.Driver.SqlClientDriver" /> > <add key="hibernate.dialect" > value="NHibernate.Dialect.MsSql2000Dialect" /> > <add key="hibernate.connection.provider" > value="NHibernate.Connection.DriverConnectionProvider" /> > <add key="hibernate.max_fetch_depth" value="3"></add> > <add key="hibernate.connection.connection_string" > value="ConnectionString = ${myConnectionString}" /> > <add key="hibernate.show_sql" value="true" /> > <add key="hibernate.search.default.directory_provider" > value="NHibernate.Search.Storage.FSDirectoryProvider, > NHibernate.Search" /> > <add key="hibernate.search.default.indexBase" > value="Index"/> > <add key="hibernate.search.analyzer" > value="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/> > </config> > </activerecord> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
