c# – 有趣的Lucene.net异常

c# – 有趣的Lucene.net异常,第1张

概述根据 this或 this,我用多个线程使用相同的indexsearcher.但是当我从FsDirectory切换到MMapDirectory时,我有一些有趣的例外. 这个工作很好: static void Main(string[] args) { DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\Tams\Deskt 根据 this或 this,我用多个线程使用相同的indexsearcher.但是当我从FsDirectory切换到MMapDirectory时,我有一些有趣的例外.

这个工作很好:

static voID Main(string[] args) {    DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\Tams\Desktop\new\");    var directory = FSDirectory.Open(directoryInfo);    var indexSearcher = new IndexSearcher(directory);    const int times = 100;    const int concurrentTaskCount = 5;    var task = new Task[concurrentTaskCount];    for (int i = 0; i < concurrentTaskCount; i++)     {        task[i] = new Task(() => Search(indexSearcher,times));        task[i].Start();    }    Task.WaitAll(task);}static voID Search(IndexSearcher reader,int times) {    List<document> docs = new List<document>(10000);    for (int i = 0; i < times; i++)     {        var q = new Term@R_404_5962@(new Term("Title","volume"));        foreach (var scoreDoc in reader.Search(q,100).scoreDocs)        {            docs.Add(reader.Doc(scoreDoc.Doc));        }    }}

但是用这个:

static voID Main(string[] args) {    DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\Tams\Desktop\new\");    var directory = new MMapDirectory(directoryInfo); // CHANGED    var indexSearcher = new IndexSearcher(directory);    const int times = 100;    const int concurrentTaskCount = 5;    var task = new Task[concurrentTaskCount];    for (int i = 0; i < concurrentTaskCount; i++)    {        task[i] = new Task(() => Search(indexSearcher,int times) {    List<document> docs = new List<document>(10000);    for (int i = 0; i < times; i++)    {        var q = new Term@R_404_5962@(new Term("Title",100).scoreDocs)        {            docs.Add(reader.Doc(scoreDoc.Doc));        }    }}

我得到各种异常,如:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative                                     and less than the size of the collection.Parameter name: indexat System.ThrowHelper.ThrowArgumentOutOfRangeException()at System.Collections.Generic.List`1.get_Item(Int32 index)at Lucene.Net.Index.FIEldInfos.FIEldInfo(Int32 fIEldNumber)    in d:\Lucene.Net\FullRepo\trunk\src\core\Index\FIEldInfos.cs:line 378   at Lucene.Net.Index.FIEldsReader.Doc(Int32 n,FIEldSelector fIEldSelector)     in d:\Lucene.Net\FullRepo\trunk\src\core\Index\FIEldsReader.cs:line 234  at Lucene.Net.Index.SegmentReader.document(Int32 n,FIEldSelector fIEldSelector)    in d:\Lucene.Net\FullRepo\trunk\src\core\Index\SegmentReader.cs:line 1193at Lucene.Net.Index.DirectoryReader.document(Int32 n,FIEldSelector fIEldSelector)    in d:\Lucene.Net\FullRepo\trunk\src\core\Index\DirectoryReader.cs:line 686at Lucene.Net.Index.IndexReader.document(Int32 n)     in d:\Lucene.Net\FullRepo\trunk\src\core\Index\IndexReader.cs:line 732at Lucene.Net.Search.IndexSearcher.Doc(Int32 i)    in d:\Lucene.Net\FullRepo\trunk\src\core\Search\IndexSearcher.cs:line 162at PerformanceTest.Program.Search(IndexSearcher reader,Int32 times)    in c:\Users\Tams\documents\Visual Studio 2012\Projects\BookCatalog\PerformanceTest\Program.cs:line 28at PerformanceTest.Program.<>c__displayClass2.<Main>b__0()    in c:\Users\Tams\documents\Visual Studio 2012\Projects\BookCatalog\PerformanceTest\Program.cs:line 43at System.Threading.Tasks.Task.InnerInvoke()at System.Threading.Tasks.Task.Execute()

要么

System.IO.IOException: read past EOFat Lucene.Net.Store.Bufferedindexinput.Refill()    in d:\Lucene.Net\FullRepo\trunk\src\core\Store\Bufferedindexinput.cs:line 179at Lucene.Net.Store.Bufferedindexinput.ReadByte()    in d:\Lucene.Net\FullRepo\trunk\src\core\Store\Bufferedindexinput.cs:line 41at Lucene.Net.Store.Indexinput.ReadVInt()    in d:\Lucene.Net\FullRepo\trunk\src\core\Store\Indexinput.cs:line 88   at Lucene.Net.Index.FIEldsReader.Doc(Int32 n,FIEldSelector fIEldSelector)    in d:\Lucene.Net\FullRepo\trunk\src\core\Index\FIEldsReader.cs:line 230  at Lucene.Net.Index.SegmentReader.document(Int32 n,FIEldSelector fIEldSelector)    in d:\Lucene.Net\FullRepo\trunk\src\core\Index\DirectoryReader.cs:line 686at Lucene.Net.Index.IndexReader.document(Int32 n)    in d:\Lucene.Net\FullRepo\trunk\src\core\Index\IndexReader.cs:line 732   at Lucene.Net.Search.IndexSearcher.Doc(Int32 i)    in d:\Lucene.Net\FullRepo\trunk\src\core\Search\IndexSearcher.cs:line 162at PerformanceTest.Program.Search(IndexSearcher reader,Int32 times)    in c:\Users\Tams\documents\Visual Studio 2012\Projects\BookCatalog\PerformanceTest\Program.cs:line 28at PerformanceTest.Program.<>c__displayClass2.<Main>b__0()    in c:\Users\Tams\documents\Visual Studio 2012\Projects\BookCatalog\PerformanceTest\Program.cs:line 43at System.Threading.Tasks.Task.InnerInvoke()at System.Threading.Tasks.Task.Execute()

最后一个代码工作正常,将concurrentTaskCount变量设置为1.

我错过了什么吗?我不明白是什么

其实我没有道路

d:\Lucene.Net\FullRepo\trunk\src\core\Store\Bufferedindexinput.cs

我甚至没有一个驱动器用字母“d”

解决方法 source for MMapDirectory显示,这个类没有按预期使用 memory-mapped files.它使用MemoryStream对象将所有索引文件加载到内存中,我猜这些流是不同线程寻找和读取时的问题的原因.

您可以通过将其加载到RAMDirectory中来获取基于内存的索引.这通过你的测试. (但是它是MMapDirectory目前所做的,不一定是你期望做的…)

var fsDirectory = FSDirectory.Open(directoryInfo);var directory = new RAMDirectory(fsDirectory);
总结

以上是内存溢出为你收集整理的c# – 有趣的Lucene.net异常全部内容,希望文章能够帮你解决c# – 有趣的Lucene.net异常所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1258020.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存