When I build the initial index from an existing database, the type of the entries in Lucene get indexed as <_hibernate_class:Castle.Proxies.MuestraProxy, DynamicProxyGenAssembly2>
However, when a new entity is added using NHibernate it gets indexed as <_hibernate_class:RALVet.Model.Muestra, RALVet>} which creates duplicate entries in Lucene, one as the real class and another one as its proxy.
I’ve tried using NHibernateUtil.GetClass() when building the index but it still returns the proxy.
This is the code that builds the initial index:
private static void CreateIndex<T>()
{
var fullTextSession =
NHibernate.Search.Search.CreateFullTextSession(BootStrapper.SessionFactory.OpenSession());
using(var tran = fullTextSession.BeginTransaction())
{
var query = fullTextSession.CreateQuery(string.Concat("from ", typeof (T).Name));
foreach (var doc in query.List())
{
fullTextSession.Index(doc);
// fullTextSession.Index(NHibernateUtil.GetClass(doc));
}
tran.Commit();
}
fullTextSession.Close();
}
Ok, I finally got it working perfectly.
The problem was that I was using an interceptor to inject the INotifyPropertyChanged implementation in my entities. Removing the interceptor made NH.Search and Lucene.net to work nicely.