I am creating a Lucene.Net based search engine application in C# with a single index. As a requirement, I need to optimize runtime for a test run with multiple (5) queries. Therefore, I wanted to use a separate thread for each search, returning results similar to this post. My code looks like this:
// 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;
However, I am getting a Lucene.Net.QueryParser.ParseException see screenshot that I do NOT get when running the searches sequentially.
Please comment if I let something unclear. I would appreciate any help on this issue.