I've nerver really delved into the search capabilites of sitecore, up until now I've always used what the previous developer used. I was looking at an issue where certain predicates didn't seem to be woking in the below piece of code:
public IEnumerable<IndexedEvent> SearchItems(Expression<Func<IndexedEvent, bool>> predicate)
using (IProviderSearchContext _context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
IEnumerable<IndexedEvent> results = _context
// use id of from the index configuration
using (IndexSearchContext indexSearchContext = SearchManager.GetIndex("my-custom-index").CreateSearchContext())
// MatchAllDocsQuery will return everything. Use proper query from the link below
SearchHits hits = indexSearchContext.Search(new MatchAllDocsQuery(), int.MaxValue);
// Get Sitecore items from the results of the query
List<Item> items = hits.FetchResults(0, int.MaxValue).Select(result => result.GetObject<Item>()).Where(item => item != null).ToList();
The question and code you are referring to with the
IndexSearchContext is from Sitecore 6. The code with the
IProviderSearchContext is for Sitecore 7 or 8 (well, 7+ that is).
So, if your code is for Sitecore8 as your tag and code example suggests, the ContentSearchManager is the way to go.