我一直在努力解決以下問題幾個小時。我試過用不同的NHibernate/NHibernate.Search程序集(3.0.0.4/2.1.2),它們都導致相同的錯誤。使用的Lucene版本是2.9.2.2NHibernate搜索Lucene.NET SearchFactory爲null
所有這些都從源代碼編譯。 NHibernate設置爲使用NHibernate Search,配置通過Fluent NHibernate。
FluentConfiguration fc = Fluently.Configure()
. (mappings, db config, etc.)
.ExposeConfiguration
(
cfg =>
{
cfg.SetProperty("hibernate.search.default.directory_provider", typeof(FSDirectoryProvider).AssemblyQualifiedName);
cfg.SetProperty("hibernate.search.default.indexBase", "~/Index");
cfg.SetProperty("hibernate.search.default.indexBase.create", "true");
cfg.SetListener(NHibernate.Event.ListenerType.PostUpdate, new FullTextIndexEventListener());
cfg.SetListener(NHibernate.Event.ListenerType.PostInsert, new FullTextIndexEventListener());
cfg.SetListener(NHibernate.Event.ListenerType.PostDelete, new FullTextIndexEventListener());
}
);
到目前爲止好,一個指數在bin文件夾(segments.gen & segments_1文件)的索引目錄中創建。
配置已經創建好之後我取NHibernate會話,並嘗試一些指標:
var _session = _factory.OpenSession();
using (ITransaction tx = _session.BeginTransaction())
{
var fts = Search.CreateFullTextSession(_session);
fts.PurgeAll(typeof(User));
var coll = fts.CreateCriteria<User>().List<User>();
foreach (var item in coll)
{
fts.Index(item);
}
tx.Commit();
}
直到fts.PurgeAll或fts.Index被擊中這又很好,這給此錯誤:
Object reference not set to an instance of an object.
Line 602: // TODO: Cache that at the FTSession level
Line 603: // not strictly necesary but a small optmization
Line 604: DocumentBuilder builder = searchFactoryImplementor.DocumentBuilders[clazz];
Line 605: if (builder != null)
Line 606: {
這個錯誤是從NHiberate.Search.dll引發的,它看起來像SearchFactory沒有初始化。應會產生SearchFactory的代碼返回null:
if (searchFactory == null)
{
searchFactory = ContextHelper.GetSearchFactory(session);
}
碰到,我需要初始化SearchFactory.Initialize的SearchFactory幾種可能的解決方案,但沒有這樣的方法在我的(2.0/3.0)NHibernate.Search組件存在。
NHibernate.Search.Search.CreateFullTextSession(_session)
.CreateFullTextQuery<User>("Firstname:Cees").List<User>();
還拋出一個 '零異常'(當然),上述呼籲:
IDictionary<System.Type, DocumentBuilder> builders = searchFactory.DocumentBuilders;
凡searchFactory == NULL
有一個SearchFactoryImpl
SearchFactoryImpl searchFactory = NHibernate.Search.Impl.SearchFactoryImpl.GetSearchFactory(config);
哪個返回一個SearchFactoryImpl實例,不知道該怎麼處理它...
也許我錯過了什麼?任何幫助深表感謝。