使用 lucene.net 2.9.2.2 构建索引

发布于 2024-10-20 23:53:10 字数 1756 浏览 1 评论 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);

仍然使用过时的代码。有人能如此友善地指出必要的改变吗?谢谢。

Christian

PS

在此处输入图像描述

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

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

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软的没边 2024-10-27 23:53:10

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

Try using FSDirectory.Open(path) instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文