I am currently upgrading a Sitecore environment from 8.0 update-2 to 8.2 update-4, but am running into some problems with our custom websearch module. This module uses the old Sitecore.Search implementation to create a Lucene index and search in it. But since 8.2 this is obsolete and I can't find the right way to upgrade this module. I used the Sitecore.Search.ISearchContext to create a custom SearchContext, but I can't find anything similar in the new ContentSearch implementation. The full code is found here: https://github.com/efocus-nl/sitecorewebsearch/blob/develop/src/FixedSearchContext.cs Has anybody already been able to fix something similar as this issue?

Kind regards, Guido


In my case, I didn't have a search context, but another solution full of old termQuery, terms, etc. Instead of rewriting the whole logic to the new LINQ implementation, we implemented a ".toLinq()" method to our main objects, and then did something like this:

A method to be able to use our objects transparently with linq:

 public static IQueryable<Result> Where(this IQueryable<Result> query, IMyObject parameter)
        var pq = PredicateBuilder.True<Result>();
        query = query.Where(parameter.ToLinq(pq));
        return query;

The we can use our objects like this:

var index = ContentSearchManager.GetIndex(indexName);
            using (var context = index.CreateSearchContext())
                var q = context.GetQueryable<Result>();
                q = q.Where(myObject);
                var results = q.GetResults<Result>();
  • Hi Vincent, thanks for your answer! Very usefull and clean code example of yours :) Jul 24 '17 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.