当前位置: 首页 > 面试题库 >

使用nHibernate v2搜索

陈夜洛
2023-03-14
问题内容

我在获取nHibernate.Search来创建索引时遇到了麻烦。

如果我使用nHibernate.dll和nHibernate.Search.dll的1.2.1.4,则可以正确创建索引,并且可以使用Luke(Lucene实用html" target="_blank">程序)对其进行检查。创建了一个segments文件以及一个Fragments文件等

但是,当我使用nHibernate.dll和nHibernate.Search.dll的v
2时,索引创建不正确。在索引目录中仅创建了一个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储存库编译的那个没有这个

所以所有排序



 类似资料:
  • 我一直在尝试使用Java的二分搜索方法在单词数组(一个词典)中搜索一个特定的字符串,然后确定该字符串是单词、前缀还是不是单词。如果返回的索引大于或等于零,则字符串为单词。如果返回的索引小于零,那么我必须确定它不是一个单词,还是一个前缀。

  • 问题内容: 我正在尝试从“关键统计信息”页面中获取有关Yahoo中的代码的信息(因为Pandas库中不支持此功能)。 AAPL示例: 编辑:谢谢安迪! 问题:这正在打印一个空数组。如何更改退货? 问题答案: 好吧,返回的列表为空的原因是因为该数据是通过单独的调用生成的,仅通过向该URL发送请求就无法完成。如果浏览Chrome / Firefox上的“网络”标签并按XHR进行过滤,则通过检查每个网络

  • 这个插件增加了搜索树中项目甚至只显示匹配节点的可能性。 您可以在API中找到所有搜索插件配置选项. $(function () { $("#plugins4").jstree({ "plugins" : [ "search" ] }); var to = false; $('#plugins4_q').keyup(function () { if(to)

  • 我在处理一个单词搜索问题。我正确地实现了dfs搜索,但在其他地方有一些琐碎的错误。

  • 问题内容: 我正在使用a 从sql数据库搜索查询。这是我的代码。 = JComboBox 但是,当我在组合框中键入一个字母时,它将添加数据库中的所有项目。我知道总是给出一个空字符串。而且,只要我键入一个字母,组合框的文本字段就会为空(我不能键入两个字母的单词)。如何解决这个问题?谢谢。 问题答案: 问题的原因如下: 始终为空是因为您在打电话之前先打电话。这意味着,在获得所选内容之前,将清除(与所选

  • 问题内容: 我对使用此代码在集合中搜索文档的效率感到好奇。随着集合中文档数量的增加和数组中项目的数量的增加,这种搜索会变得非常低效吗?是否有更好的方法可以执行此操作,或者可以对数据库进行模式更改以更好地优化此方法?在哪里可以找到Firestore文档的这些功能的时间复杂性? 我最初想尝试将组ID存储在该用户下,以便仅抓取该当前用户的组,但是遇到了问题,却从未找到使用多个ID进行查询来设置FireS