lucene - 如何优化 Lucene.Net 索引

标签 lucene lucene.net

我需要索引大约 10GB 的数据。我的每个“文档”都非常小,想想有关产品的基本信息,大约 20 个数据字段,大多数只有几个字。仅对 1 列进行索引,其余列进行存储。我正在从文本文件中获取数据,因此这部分速度非常快。

目前的索引速度仅为每小时 40mb 左右。我听其他人说他们的成就比这快 100 倍。对于较小的文件(大约 20mb),索引速度相当快(5 分钟)。然而,当我让它循环遍历我的所有数据文件(大约 50 个文件,总计 10GB)时,随着时间的推移,索引的增长似乎减慢了很多。关于如何加快索引速度或者最佳索引速度是多少有什么想法吗?

顺便说一句,我注意到 .Net 端口中的 API 似乎并不包含与 Java 中原始 API 相同的所有方法...

更新 - 以下是索引 C# 代码的片段: 首先我设置一下:

            directory = FSDirectory.GetDirectory(@txtIndexFolder.Text, true);
            iwriter = new IndexWriter(directory, analyzer, true);
            iwriter.SetMaxFieldLength(25000);
            iwriter.SetMergeFactor(1000);
            iwriter.SetMaxBufferedDocs(Convert.ToInt16(txtBuffer.Text));

然后从制表符分隔数据文件中读取:

    using (System.IO.TextReader tr = System.IO.File.OpenText(File))
    {
        string line;
        while ((line = tr.ReadLine()) != null)
        {
            string[] items = line.Split('\t');

然后创建字段并将文档添加到索引:

                fldName = new Field("Name", items[4], Field.Store.YES, Field.Index.NO);
                doc.Add(fldName);
                fldUPC = new Field("UPC", items[10], Field.Store.YES, Field.Index.NO);
                doc.Add(fldUPC);
                string Contents = items[4] + " " + items[5] + " " + items[9] + " " + items[10] + " "  + items[11] + " " + items[23] + " " + items[24];
                fldContents = new Field("Contents", Contents, Field.Store.NO, Field.Index.TOKENIZED);
                doc.Add(fldContents);
                ...
                iwriter.AddDocument(doc);

一旦完全完成索引:

    iwriter.Optimize();
    iwriter.Close();

最佳答案

显然,我已经下载了一个 3 年前的 Lucene 版本,由于某种原因,该版本在项目主页上显着地链接到...下载了最新的 Lucene 源代码,编译,使用了新的 DLL,修复了以下问题一切。文档有点糟糕,但价格合适而且速度很快。

来自helpful blog

First things first, you have to add the Lucene libraries to your project. On the Lucene.NET web site, you’ll see the most recent release builds of Lucene. These are two years old. Do not grab them, they have some bugs. There has not been an official release of Lucene for some time, probably due to resource constraints of the maintainers. Use Subversion (or TortoiseSVN) to browse around and grab the most recently updated Lucene.NET code from the Apache SVN Repository. The solution and projects are Visual Studio 2005 and .NET 2.0, but I upgraded the projects to Visual Studio 2008 without any issues. I was able to build the solution without any errors. Go to the bin directory, grab the Lucene.Net dll and add it to your project.

关于lucene - 如何优化 Lucene.Net 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3887941/

相关文章:

lucene - Mac 上安装 Lucene 的步骤是什么?

java - Solr(php 与 java): query differences when determining number of documents

search - 使用 Lucene.NET 在通配符搜索中转义特殊字符

.net-core - 使用 DotNetRDf.Query.FullText 创建 Lucene 索引器时出现异常

solr - 匹配Titan索引的elasticsearch数据

Java 死锁 : are there cases where it is not a bug?

java - 如何获取 Lucene(5.3) 生成的特定术语的位置

lucene - 是否可以遍历存储在 Lucene Index 中的文档?

full-text-search - Lucene标准分析仪vs Snowball

azure - Lucene .NET 3 和 Azure : unable to complete indexing