hibernate - nHibernate.Search 使用 nHibernate v2

标签 hibernate nhibernate lucene hibernate-search nhibernate.search

我在让 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);

这创建了索引的基本框架,但无法使用 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吗?在这种情况下我做错了什么?

网络上对此的了解很少。

有人吗?

最佳答案

我在这里找到了一个工作示例:

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

此项目中的 v2 nHibernate.Search.dll 确实包含 SearchFactory(尽管位于不同的命名空间中)。

我从SVN存储库编译的没有这个

一切都已排序

关于hibernate - nHibernate.Search 使用 nHibernate v2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/426151/

相关文章:

java - 关于 JPA TABLE_PER_CLASS 和子实体 id

Java 泛型 - Class<?> 构造函数参数问题

java - 如何在 Hibernate 中将子类映射到父类?

java - 使用 GenerationType.TABLE 在重新启动时 hibernate 重复主键

java - 为什么 Lucene Token Filter 类必须声明为 "final"?

nhibernate - 在选择 ORM 时,LINQ to SQL 或 LINQ to Entities 是否比 NHibernate 更好?

nhibernate - 这个单向NHibernate一对一映射怎么做?

.net - NHibernate 的 Windows 服务中的多个 SessionFactories

solr - 在哪里可以找到 Apache Lucene/Solr 的性能基准

elasticsearch - 在ELK中的特定位置匹配子字符串电子邮件地址