하나의 색인으로 Lucene.Net 기반 검색 엔진 응용 프로그램을 C#으로 만듭니다. 요구 사항으로는 여러 (5) 개의 쿼리로 테스트 실행을 위해 런타임을 최적화해야합니다. 따라서 검색 할 때마다 별도의 스레드를 사용하여 this 게시물과 비슷한 결과를 반환하고 싶습니다. 내 코드는 다음과 같습니다Lucene.Net Parallel Search
// load information needs
List<InformationNeed> informationNeeds = FileReader.readInformationNeeds(collectionPath);
// each search has its own thread referenced in this list
List<Thread> threadList = new List<Thread>();
// each search has its own result referenced in this list
List<SearchResult> searchResults = new List<SearchResult>();
foreach (InformationNeed informationNeed in informationNeeds){
// create searchOptions
SearchOptions searchOptions = new SearchOptions(DEBUG_pre_processQuery, informationNeed.getInput());
// run search
SearchResult result = null; // Used to store the return value
var thread = new Thread(
() =>
{
result = startSearch(searchOptions);
Console.WriteLine("end search for IN nr " + informationNeed.getID() + "results = " + result);
//add results to list
searchResults.Add(result);
});
thread.Start();
threadList.Add(thread);
}
// block main thread until all threads finished
foreach (Thread t in threadList){
t.Join();
}
return searchResults;
을하지만, 내가 순차적으로 검색을 실행할 때 내가되지 않는 Lucene.Net.QueryParser.ParseException see screenshot을 얻고있다.
내가 무엇인가 불분명하게한다면 의견을 말하십시오. 이 문제에 대한 도움을 주시면 감사하겠습니다.
'searchResults'에 대한 액세스를 동기화하지 않습니다. 그것은 문제를 일으킬 것입니다. –