Gravatar for

Question by ncipollina, Dec 2, 2015 3:42 PM

Coveo Default Provider Linq Query

One of the neat little tricks that I have learned recently is that when searching in an index in Sitecore, you can retrieve the index from the Sitecore item itself with this code:

using (var ctx = ContentSearchManager.GetIndex((SitecoreIndexableItem)item).CreateSearchContext())
    // search code here

The problem I'm running into is that when I do this I'm getting the Lucene index instead of the Coveo index and I'd really like to search the Coveo index. Rather then specifying "coveomasterindex" in the GetIndex call, is there a way I can default to Coveo's index?

Thanks in advance, Nick

1 Reply
Gravatar for

Answer by Luc Bergeron, Dec 2, 2015 5:01 PM


You can get only the Coveo indexes by leveraging the Coveo.SearchProvider.ContentSearch.CoveoIndexFetcher, Coveo.SearchProviderBase class. It exposes methods that are similar to the one exposed by ContentSearchManager but it ensures you will retrieve only Coveo indexes.

You can use it this way:

var indexFetcher = new Coveo.SearchProvider.ContentSearch.CoveoIndexFetcher();
using (var ctx = indexFetcher.GetCoveoSearchIndex((SitecoreIndexableItem) item).CreateSearchContext())
    // search code


Gravatar for

Comment by ncipollina, Dec 3, 2015 5:05 PM

Thank you. That was exactly what I was looking for!

Ask a question