nHibernate.Search を取得してインデックスを作成するのに問題があります。
nHibernate.dll & nHibernate.Search.dll の 1.2.1.4 を使用すると、インデックスが正しく作成され、Luke (Lucene ユーティリティ) で検査できます。セグメント ファイルとフラグメント ファイルなどが作成されます。
ただし、nHibernate.dll & nHibernate.Search.dll の v 2 を使用すると、インデックスが正しく作成されません。Index ディレクトリには 1k セグメント ファイルのみが作成され、Luke はそれを調べることができません。
v1 で使用したコードは次のとおりです。
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof (Contact).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
SearchFactory.Initialize(_configuration, _sessionFactory);
そして、設定ファイルに次のものがあります
<property name="hibernate.search.default.directory_provider">NHibernate.Search.Storage.FSDirectoryProvider, NHibernate.Search</property>
<property name="hibernate.search.default.indexBase">~/Index</property>
バージョン 2 には SearchFactory がありません。私が見つけた唯一の同様のものは
SearchFactoryImpl.GetSearchFactory(_configuration);
だから私は次のように構成を設定しました
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof (Contact).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
_configuration.SetProperty("hibernate.search.default.directory_provider",
"NHibernate.Search.Store.FSDirectoryProvider, NHibernate.Search");
_configuration.SetProperty("hibernate.search.default.indexBase", "Index");
_configuration.SetProperty("hibernate.search.analyzer",
"Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net");
_configuration.SetListener(ListenerType.PostUpdate, new FullTextIndexEventListener());
_configuration.SetListener(ListenerType.PostInsert, new FullTextIndexEventListener());
_configuration.SetListener(ListenerType.PostDelete, new FullTextIndexEventListener());
SearchFactoryImpl.GetSearchFactory(_configuration);
これにより、インデックスの最低限の骨が作成されますが、ルークでは表示できません-破損していることがわかります
また、次のコードを使用してインデックスを手動で作成しようとしましたが、ここでもセグメント ファイルのみが作成され、他には何も作成されません。
public void CreateIndex<T>(string rootIndexDirectory)
{
Type type = typeof (T);
var info = new DirectoryInfo(Path.Combine(rootIndexDirectory, type.Name));
// Recursively delete the index and files in there
if (info.Exists) info.Delete(true);
// Now recreate the index
FSDirectory dir = FSDirectory.GetDirectory(Path.Combine(rootIndexDirectory, type.Name), true);
//Ioc.UrlProvider.MapPath(Path.Combine(rootIndexDirectory, type.Name)), true);
try
{
var writer = new IndexWriter(dir, new StandardAnalyzer(), true);
writer.Close();
}
finally
{
if (dir != null)
dir.Close();
}
using (ISession session = _sessionFactory.OpenSession())
{
using (IFullTextSession fullTextSession = Search.CreateFullTextSession(session))
{
foreach (var contact in _contacts)
{
//session.Save(contact);
fullTextSession.Index(contact);
}
}
}
}
私の質問は、nHibernate.Search を使用したい場合、nHibernate の v1.1.4 を使用する必要がありますか? または、v2 を使用できますか? どのような場合、私は何を間違っていますか?
これについては、ウェブ上にはほとんどありません。
誰?