3

我无法获得nHibernate.Search创建索引。nHibernate.Search与nHibernate v2

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

但是,当我使用nHibernate.dll的第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); 

和我有在配置文件中

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

这将创建一个索引的基本框架,但它是不可见的卢克 - 这告诉我它已损坏

我也用下面的代码来尝试手动创建索引,但同样只创建段文件,没有别的

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

网上很少有关于此。

有人吗?

+0

有人请更改标题nhibrnate NHibernate的 – Cherian 2009-03-21 16:24:53

回答

2

我已经找到了工作示例这里:

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

在这个项目的确包含一个SearchFactory(尽管是在不同的命名空间)的V2 nHibernate.Search.dll。

一个我从SVN仓库犯规编有这个

因此,所有分类

+0

良好的工作家伙。谢谢! – andy 2010-12-15 02:33:37