I have switched to SOLR search in Sitecore 8.1 and everything is fine (indices rebuild normally). However, when I search for items using the SearchContext
I get no results when I filter according to item.Path.Contains("")
although it worked using Lucene. If I remove the item.Path.Contains("")
, I get results. So, why doesn't it work?
This is the code used:
List<NewsSearchResultItem> results = new List<NewsSearchResultItem>();
var index = ContentSearchManager.GetIndex("sitecore_web_index");
using (IProviderSearchContext context = index.CreateSearchContext())
{
var tempResults = context.GetQueryable<NewsSearchResultItem>()
.Where(item => item.Path.Contains("/sitecore/content/News"))
.Take(10);
results = tempResults.ToList();
}
return results.Select(s => new NewsViewModel(s.GetItem())).ToList();
Solr with Sitecore stores text fields as lowercase fields by default.
Change your
Where
clause to usepath/toLower()
:Also remember to add filters to use your current language only - there might be some documents in Solr for Sitecore items despite the fact that they don't have any versions in a particular language.