nHibernate.Search与nHibernate v2 [英] nHibernate.Search with nHibernate v2

查看:131
本文介绍了nHibernate.Search与nHibernate v2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让nHibernate.Search创建一个索引。



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

然而,当我使用nHibernate.dll& amp; amp; nHibernate.Search.dll然后索引不正确创建。在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。我能找到的唯一类似的事情是:

pre $ 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));

//递归删除那里的索引和文件
if(info.Exists)info.Delete(true);

//现在重新创建索引
FSDirectory dir = FSDirectory.GetDirectory(Path.Combine(rootIndexDirectory,type.Name),true);
//Ioc.UrlProvider.MapPath(Path.Combine(rootIndexDirectory,type.Name)),true);

尝试
{
var writer = new IndexWriter(dir,new StandardAnalyzer(),true);
writer.Close();
}
finally
{
if(dir!= null)
dir.Close();
}

using(IFession 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吗?在这种情况下,我做错了什么?



网上很少有关于此的信息。



任何人?

解决方案

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

< a href =http://darioquintana.com.ar/blogging/?p=21 =nofollow noreferrer> http://darioquintana.com.ar/blogging/?p=21

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



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



因此所有的排序


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?

解决方案

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

这篇关于nHibernate.Search与nHibernate v2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆