Question

Im building a search function for an application with Lucene.NET and NHibernate.Search. To index the existing data I am using this method:

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

Where I have marked the fields I want to index with following attribute:

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

But when I then inspect the indicies in Luke the fields still have uppercases, commas etc. which should have been removed by the StandardAnalyzer.

Does anyone have know what I am doing wrong?

Was it helpful?

Solution

I had similiar problem to yours, but I've been trying to use WhitespaceAnalyzer. Setting it in Field attribute didn't work for me either.

I've ended up setting it globally. I am using FluentNHibernate for configuration and it looks like that:

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

Take a look at NHibernate.Search.Environment.AnalyzerClass. Funny thing is that it won't work for generic fulltext queries (i think that Lucene will use StandardAnalyzer), but that's another story :).

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top