在对数据进行索引时,StandardAnalyzer似乎没有参与,NHibernate.Search

时间:2011-04-27 10:14:06

标签: lucene.net nhibernate.search

使用Lucene.NET和NHibernate.Search为应用程序构建搜索功能。要索引现有数据我正在使用此方法:

public void SynchronizeIndexForAllUsers()
    {
        var fullTextSession = Search.CreateFullTextSession(m_session);
        var users = GetAll();
        foreach (var user in users)
        {
            if (!user.IsDeleted)
            {
                fullTextSession.Index(user);
            }
        }
    }

我已使用以下属性标记了要索引的字段:

[Field(Index.Tokenized, Store = Store.Yes, Analyzer = typeof(StandardAnalyzer))]
public virtual string FirstName
    {
        get { return m_firstName; }
        set { m_firstName = value; }
    }

但是当我接着检查Luke中的标记时,字段仍然有大写字母,逗号等应该由StandardAnalyzer删除。

有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,但我一直在尝试使用WhitespaceAnalyzer。在Field属性中设置它对我来说也不起作用。

我最终全局设置了它。我正在使用FluentNHibernate进行配置,它看起来像这样:

this._sessionFactory =
    Fluently.Configure()
    .Database(MsSqlConfiguration.MsSql2005
        .ConnectionString(cs => cs
        // cut
    .ShowSql()
     )
     .Mappings(m => m.FluentMappings
     // cut
     )
     .ExposeConfiguration(cfg =>
     {
         // important part: lucene.net and nhibernate.search
         cfg.SetProperty("hibernate.search.default.directory_provider", typeof(NHibernate.Search.Store.FSDirectoryProvider).AssemblyQualifiedName);
         cfg.SetProperty("hibernate.search.default.indexBase", @"~\Lucene");
         cfg.SetProperty("hibernate.search.indexing_strategy", "event");
         cfg.SetProperty(NHibernate.Search.Environment.AnalyzerClass, typeof(WhitespaceAnalyzer).AssemblyQualifiedName);
         cfg.SetListener(NHibernate.Event.ListenerType.PostUpdate, new FullTextIndexEventListener());
         cfg.SetListener(NHibernate.Event.ListenerType.PostInsert, new FullTextIndexEventListener());
         cfg.SetListener(NHibernate.Event.ListenerType.PostDelete, new FullTextIndexCollectionEventListener());
     })
     .BuildSessionFactory();

看看NHibernate.Search.Environment.AnalyzerClass。有趣的是,它不适用于通用全文查询(我认为Lucene将使用StandardAnalyzer),但这是另一个故事:)。

希望这有帮助。

相关问题