這是一個棘手的問題:我想通過Lucene搜索結果進行延遲加載。可能?Lucene.NET和懶加載
這裏是我的代碼:
public IEnumerable<BizObj> Search(string query)
{
var parsedQuery = new QueryParser(...).Parse();
var searcher = new IndexSearcher(parsedQuery, storage);
try
{
var hits = searcher.Search(parsedQuery);
// Hooray for LINQ's lazy-evaluated Select method!
// But oh noes!! searcher will be closed by the time it
// gets executed, thus resulting in an exception. :-(
return hits.Select(hit => PullBizObjectFromDatabase(hit));
}
finally
{
searcher.Close();
}
}
消費代碼:
var searchResults = from result in blah.Search("hello, world!")
where SomeBizLogic(result)
select result;
// Print the top 50 search results.
foreach (var result in searchResults.Take(50))
{
// Exception! The searcher field inside Search(...) has been closed! :-(
Console.WriteLine(result);
}
我的問題是,如何從Lucene的我懶加載搜索結果?
謝謝,但那不是我正在尋找的。我在下面回答了我自己的問題。 – 2010-01-21 03:52:20