首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用nHibernate v2的nHibernate.Search

使用nHibernate v2的nHibernate.Search
EN

Stack Overflow用户
提问于 2009-01-08 21:51:58
回答 1查看 1.3K关注 0票数 3

我在让nHibernate.Search创建索引时遇到了问题。

如果我使用nHibernate.dll & nHibernate.Search.dll的1.2.1.4,那么索引是正确创建的,并且我可以使用Luke (一个Lucene实用程序)检查它。将创建片段文件以及片段文件等

但是,当我使用nHibernate.dll & nHibernate.Search.dll的v2时,索引不能正确创建。索引目录中只创建了一个1k段的文件,Luke无法对其进行检查。

我在v1中使用的代码如下:

代码语言:javascript
复制
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof (Contact).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
SearchFactory.Initialize(_configuration, _sessionFactory);

我在配置文件中有以下内容

代码语言:javascript
复制
<property name="hibernate.search.default.directory_provider">NHibernate.Search.Storage.FSDirectoryProvider, NHibernate.Search</property>
<property name="hibernate.search.default.indexBase">~/Index</property>

在版本2中没有SearchFactory。我能找到的唯一相似的东西是

代码语言:javascript
复制
SearchFactoryImpl.GetSearchFactory(_configuration);

因此,我已经按如下方式设置了配置

代码语言:javascript
复制
_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文件,没有创建其他文件

代码语言:javascript
复制
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吗?在哪种情况下,我做错了什么?

在网络上关于这方面的东西很少。

有没有人?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-01-09 00:25:59

我在这里找到了一个有效的例子:

http://darioquintana.com.ar/blogging/?p=21

此项目中的v2 nHibernate.Search.dll确实包含SearchFactory (尽管使用了不同的名称空间)。

我从SVN存储库编译的代码没有这样的代码

所以都排序好了

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/426151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档