Search Sitecore 7 Search cannot access the located object

I worked with some Sitecore 7 search code. Example below.

using (var context = Index.CreateSearchContext()) { // ....Build predicates var query = context.GetQueryable<SearchResultItem>().Where(predicate); return query.GetResults(); } 

This works fine in SOLR, but when used with standard Lucene, when I refer to the property in SearchResults<SearchResultItem> returned by GetResults() , Sitecore errors with " Cannot access a disposed object ". It seems that GetResults() not enumerating and is still hanging in searchcontext.

Does anyone come across this before and know how to fix it? I have seen some articles suggesting that SearchContext in the state of the application, but ideally I want to avoid this.

thanks

Yang

+7
search lucene sitecore
source share
2 answers

It seems that SearchResults<T> contains a link to SearchHit , and LuceneSearchProvider does not open the reader. The new version of Lucene automatically closes the reader. I think you can return the wrong type. You should probably do the following:

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

However, make sure that they do not return too much. You should probably use take (), etc.

+7
source share

Is GetResults() return of List or IEnumerable / IQueryable ?

Try returning the list if it has not been.

 return query.GetResults().ToList(); 

Greetings

0
source share

All Articles