开发者

build index using lucene.net 2.9.2.2

I have to use lucene.net 2.9.2.2 with NHibernate 3.0. I have started to edit this old code:

public void BuildSearchIndex()
{

    FSDirectory entityDirectory = null;
    IndexWriter writer = null;

    var entityType = typeof(MappedSequence);

    var indexDirectory = new DirectoryInfo(GetIndexDirectory());

    if (indexDirectory.Exists)
    {
    indexDirectory.Delete(true);
    }

    try
    {
    entityDirectory = FSDirectory.GetDirectory(Path.Combine(indexDirectory.FullName, entityType.Name), true);
    writer = new IndexWriter(entityDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true, IndexWriter.MaxFieldLength.UNLIMITED);
    }
    finally
    {
    if (entityDirectory != null)
    {
        entityDirectory.Close();
    }

    if (writer != null)
    {
        writer.Close();
    }
    }

    IFullTextSession fullTextSession = Search.CreateFullTextSession(this.Session);
    // Iterate through Suppliers and add them to Lucene's index
    foreach (MappedSequence instance in Session.CreateCriteria(typeof(MappedSequence)).List<Mapped开发者_JAVA百科Sequence>())
    {
    fullTextSession.Index(instance);
    }
}

private string GetIndexDirectory()
{
    INHSConfigCollection nhsConfigCollection = CfgHelper.LoadConfiguration();
    string property = nhsConfigCollection.DefaultConfiguration.Properties["hibernate.search.default.indexBase"];
    var fi = new FileInfo(property);
    return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fi.Name);
} 

to build the index. The line:

FSDirectory.GetDirectory(Path.Combine(indexDirectory.FullName, entityType.Name), true);

still uses obsolete code. Could anyone be so kind and point out the necessary change. Thanks.

Christian

PS

build index using lucene.net 2.9.2.2


Try using FSDirectory.Open(path) instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜