I am using regular ContentSearch API in front of Coveo for Sitecore 3
(not using Coveo UI). I am trying to boost keywords in Title
and Subtitle
fields to have higher weights compared to page Content
. Unfortunately my current approach does not seem to work. Ideally I would like to see results that has keywords match in Title field to show up on top of search results.
Is there another way to weigh certain fields over others in Coveo and ContentSearch?
private Expression<Func<T, bool>> GetPredicate<T>(string criteria, string location, string language) where T : SearchResultItem
{
var predicate = PredicateBuilder.True<T>();
predicate = predicate.And(
x => x.Language == language);
predicate = predicate.And(
x => x.Path.Contains(location));
predicate = predicate.And(
x => x.TemplateId == TemplateIds.ArticlePageTemplateId
|| x.TemplateId == TemplateIds.GroupPageTemplateId);
var termPredicate = PredicateBuilder.True<T>();
foreach (var term in criteria.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
{
termPredicate = termPredicate.And(p => p.Content.Contains(term)
|| p["Title"].Contains(term).Boost(3f)
|| p["Subtitle"].Contains(term).Boost(2f));
}
predicate = predicate.And(termPredicate);
return predicate;
}