我有一个解析查询来找到lucene.net与文件操作一起的单词,并在顺序操作查询解析器工作正常,当我使用Parallel.Foreach循环执行相同的操作我得到解析器异常。 下面的两个代码示例。Lucene.Net异常,同时在Parallel.ForEach循环解析查询<EOF>
工作代码:
#region - Non Parallel Execution -
using (var input = File.OpenText(file.FullName))
{
using (var swFile = new StreamWriter(decryptingFilename))
{
while ((line = input.ReadLine()) != null)
{
totalEncryptedContact++;
query = queryParser.Parse(line.Trim());
TopDocs resultDocs = searcher.Search(query, 1);
if (resultDocs.ScoreDocs.Count() > 0)
{
hits = resultDocs.ScoreDocs[0];
var documentFromSearcher = searcher.Doc(hits.Doc);
string msisdn = documentFromSearcher.Get("MSISDN");
if (!string.IsNullOrWhiteSpace(msisdn))
{
swFile.WriteLine(msisdn);
totalDecryptedContact++;
}
}
}
}
}
#endregion - Non Parallel Execution -
异常代码与并行:
using (var swFile = new StreamWriter(decryptingFilename))
{
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = 4;
Parallel.ForEach(File.ReadLines(file.FullName), options, newline =>
{
totalEncryptedContact++;
query = queryParser.Parse(QueryParser.Escape(newline.Trim()));
TopDocs resultDocs = searcher.Search(query, 1);
if (resultDocs.ScoreDocs.Count() > 0)
{
hits = resultDocs.ScoreDocs[0];
var documentFromSearcher = searcher.Doc(hits.Doc);
string msisdn = documentFromSearcher.Get("MSISDN");
if (!string.IsNullOrWhiteSpace(msisdn))
{
swFile.WriteLine(msisdn);
totalDecryptedContact++;
}
}
});
}
例外: 类型的异常 'Lucene.Net.QueryParsers.ParseException' 发生在Lucene.Net.dll但在用户代码没有处理
其他信息:无法解析“7465”:遇到“”在第1行,第4栏
期待之一:
"(" ...
"*" ...
"^" ...
<QUOTED> ...
<TERM> ...
<FUZZY_SLOP> ...
<PREFIXTERM> ...
<WILDTERM> ...
"[" ...
"{" ...
<NUMBER> ...
":" ...
":" ...
":" ...
":" ...
":" ...
":" ...
":" ...
":" ...
<TERM> ...
"*" ...