3

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;
    }
2

Coveo should support .Boost() like Lucene as mentioned in the supported LINQ operators.

I do not know if this applies to your use case, but it is worth noting that Coveo for Sitecore ships with a specific CoveoBoost extension that supports boosting results according to fields like so:

queryable.CoveoBoost(item => item.Field == "value" || item.Field2 == "value2", 200)

Note that your number should be high enough, we consider around 100 to be a "great boost", so you should probably try with higher numbers too.

| improve this answer | |
  • Unfortunately I cannot use CoveoBoost because of the way the predicate is setup. I though the Boost works as well but doesnt look like. – xoail Jan 11 '17 at 23:54
  • Did you try a bigger number..? – flguillemette Jan 17 '17 at 20:42
1

Sitecore's LINQ .Contains method translates to a WildcardQuery, which can't be boosted in native Lucene.

You can check the Lucene.Net question here: https://stackoverflow.com/questions/10352404/lucene-net-boost-not-working-when-using-wildcard

As Sitecore depends on the Lucene.Net, wildcard queries boosting won't work here.

However, boosing still works on exact matches, like Equals, etc.

| improve this answer | |
  • Thanks, Is this same for Coveo? What is the best way to perform this kind of boosting then? – xoail Jan 11 '17 at 18:29
  • @xoail I believe yes. You can try field boosting from this article community.sitecore.net/technical_blogs/b/sitecorejohn_blog/… – Andrey Bobrov Jan 11 '17 at 18:54
  • This field boosting seems to be only applicable to Lucene since its talking about adding it to Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config. Not sure how it would affect Coveo. – xoail Jan 11 '17 at 19:15
  • @xoail this was just an example for lucene. you can do that in the coveo configuration – Andrey Bobrov Jan 11 '17 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.