I'm working on the Sitecore ContentSearch API.I have indexed a set of fields in an Item.is it possible to query more than one fields at the same time?
public static List<MovieSearchResultItem> SearchResults(string txtQuery)
{
using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
{
var query = context.GetQueryable<MovieSearchResultItem>().Where(result => result.Body.Contains(txtQuery)).ToList();
return query;
}
}
In the above query I'm just using the Body field.how to include more than one fields.My search data might be title or body or someother field so i want to check all three fields.
Try to add another condition to the Where
clause:
var query = context.GetQueryable<MovieSearchResultItem>()
.Where(result => result.Body.Contains(txtQuery)
|| result.Title.Contains(txtQuery)
|| result.OtherField.Contains(txtQuery)).ToList();