我在让nHibernate.Search创建索引时遇到了问题。
如果我使用nHibernate.dll & nHibernate.Search.dll的1.2.1.4,那么索引是正确创建的,并且我可以使用Luke (一个Lucene实用程序)检查它。将创建片段文件以及片段文件等
但是,当我使用nHibernate.dll & nHibernate.Search.dll的v2时,索引不能正确创建。索引目录中只创建了一个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);这将创建索引的基本框架,但无法使用Luke查看它-这告诉我它已损坏
我还使用了以下代码尝试手动创建索引,但它同样只创建了segments文件,没有创建其他文件
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的1.1.4版吗?或者我可以使用v2吗?在哪种情况下,我做错了什么?
在网络上关于这方面的东西很少。
有没有人?
发布于 2009-01-09 00:25:59
我在这里找到了一个有效的例子:
http://darioquintana.com.ar/blogging/?p=21
此项目中的v2 nHibernate.Search.dll确实包含SearchFactory (尽管使用了不同的名称空间)。
我从SVN存储库编译的代码没有这样的代码
所以都排序好了
https://stackoverflow.com/questions/426151
复制相似问题