search - Sitecore 7 搜索,无法访问已处置的对象

标签 search lucene sitecore

我一直在使用一些 Sitecore 7 搜索代码。下面的例子。

using (var context = Index.CreateSearchContext())
{
    // ....Build predicates

    var query = context.GetQueryable<SearchResultItem>().Where(predicate); 
    return query.GetResults();
}

这在 SOLR 中工作得很好,但是当与标准 Lucene 一起使用时,每当我引用 SearchResults<SearchResultItem> 中的属性时返回者 GetResults() ,Sitecore 错误为“Cannot access a disposed object”。看来GetResults()不枚举并且仍然保留搜索上下文。

有人以前遇到过这个问题并知道如何解决吗?我看过一些文章建议拥有 SearchContext在应用程序状态下,但理想情况下我想避免这种情况。

谢谢

伊恩

最佳答案

看来SearchResults<T>引用 SearchHitLuceneSearchProvider不让读者保持开放状态。新版本的Lucene会自动关闭reader。我认为您可能返回了错误的类型。你可能应该这样做:

var query = context.GetQueryable<SearchResultItem>().Where(predicate);
return query.ToList();

但是请确保不会返回太多。您可能应该使用 take() 等。

关于search - Sitecore 7 搜索,无法访问已处置的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21827441/

相关文章:

Sitecore 性能增强

compression - Sitecore 'getMediaStream' 无法正常工作

java - 卢塞恩 : Delete by ID not working

android - 您可以使用 Intent 搜索 Google Play 吗?

unit-testing - Lucene 单元测试

lucene - apache solr : sum of data resulted from group by

python - 搜索 Pandas 数据框,在 find 上开始新搜索

android - 过滤自定义ArrayAdapter或在 Activity 中实现搜索

Solr 突然消耗整个堆

Sitecore/玻璃映射器 : how to return query in order of content tree