0

我必须将 lucene.net 2.9.2.2 与 NHibernate 3.0 一起使用。我已经开始编辑这个旧代码:

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<MappedSequence>())
    {
    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);
} 

建立索引。该行:

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

仍然使用过时的代码。谁能如此友善并指出必要的改变。谢谢。

基督教

附言

在此处输入图像描述

4

1 回答 1

0

尝试使用 FSDirectory.Open(path) 代替。

于 2011-03-08T14:08:31.573 回答