nHibernate.Search 使用 nHibernate v2
我无法让 nHibernate.Search 创建索引。
如果我使用 1.2.1.4 的 nHibernate.dll & nHibernate.Search.dll 然后索引被正确创建,我可以使用 Luke(一个 Lucene 实用程序)检查它。 创建一个段文件以及一个片段文件等
但是,当我使用 nHibernate.dll 的 v 2 时 nHibernate.Search.dll 那么索引没有正确创建。 Index 目录中仅创建了一个 1k 段文件,Luke 无法检查它。
我在 v1 中使用的代码如下:
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof (Contact).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
SearchFactory.Initialize(_configuration, _sessionFactory);
在版本 2 的配置文件中,我有以下内容,
<property name="hibernate.search.default.directory_provider">NHibernate.Search.Storage.FSDirectoryProvider, NHibernate.Search</property>
<property name="hibernate.search.default.indexBase">~/Index</property>
没有 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 无法查看它 - 这告诉我它已损坏
我还使用了以下代码来尝试创建手动索引,但它又只创建段文件,没有别的
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吗? 在这种情况下我做错了什么?
网上关于这方面的资料很少。
任何人?
I having trouble getting nHibernate.Search to create an Index.
If I use 1.2.1.4 of nHibernate.dll & nHibernate.Search.dll then the index is created correctly and I can inspect it with Luke (a Lucene utility).
A segments file is created as well as a Fragments file etc
However, when I use v 2 of nHibernate.dll & nHibernate.Search.dll then the index is not created correctly. Only a 1k segments file is created in the Index directory and Luke is unable to inspect it.
The code I used in v1 was as follows:
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof (Contact).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
SearchFactory.Initialize(_configuration, _sessionFactory);
and I have the following in the config file
<property name="hibernate.search.default.directory_provider">NHibernate.Search.Storage.FSDirectoryProvider, NHibernate.Search</property>
<property name="hibernate.search.default.indexBase">~/Index</property>
in version 2 there is no SearchFactory. The only similar thing I could find was
SearchFactoryImpl.GetSearchFactory(_configuration);
So I have set up the config as follows
_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);
This creates the bare bones of an Index but it is not viewable with Luke - which tells me it is corrupt
I have also used the following code to try and create the index manually, but again it only creates the segments file, nothing else
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);
}
}
}
}
So my question is - do I have to use v1.1.4 of nHibernate if I want to use nHibernate.Search?
Or can I use v2? In which case what am I doing wrong?
There is very little on the web about this.
Anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里找到了一个工作示例:
http://darioquintana.com.ar/blogging/? p=21
此项目中的 v2 nHibernate.Search.dll 确实包含 SearchFactory(尽管位于不同的命名空间中)。
我从SVN存储库编译的没有这个
所以全部排序
I have found a working example here:
http://darioquintana.com.ar/blogging/?p=21
The v2 nHibernate.Search.dll in this project does contain a SearchFactory (albeit in a different namespace).
The one I compiled from the SVN repository doesnt have this
So all sorted