我有一個解析查詢來找到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> ...
"*" ...