I'm working on the site search module where the user searches for a particular item.
Currently, the site searches and matches only the item name.
But I'm trying for searching the keyword in item fields also(If any field contains the search value that one also needs to return).
How I achieve this? Is there any API available for this?
Attaching the code.
var Index = ContentSearchManager.GetIndex("sitecore_" + IndexName + "_index");
using (var context = Index.CreateSearchContext())
{
var allItems = context.GetQueryable<SearchResultItem>().ToList();
var searchResults = allItems.Where(x => x.Path.ToLower().Contains(pathToBeSearch) && x.Name.ToLower().Contains(searchkey.ToLower())).ToList();
}
ToList()
on theIQueryable
will invoke the search call at that point, and then your subsequent calls will be doing standard LINQ operations on a giant in-memory list. You should be doing theToList()
AFTER your LINQ statements so that they get translated to Lucene/SOLR statements. Either you copied from the Sitecore coursebook incorrectly, or the coursebook is incorrect.