5

We're using the content search api to search through our Azure Search index, everything works fine but boosting does not work. However, when we switch from Azure search provider config to the Lucene search provider config boosting works, so we think it's because of azure.

The Content Search Code:

        var tags = GetTagsFromSomewhere();

        using (var context = SearchIndexResolver.GetIndex(ContextItem).CreateSearchContext())
        {
            var queryable = context.GetQueryable<CustomType>();

            var predicat = PredicateBuilder.False<BaseIndexModel>();

            foreach (var tag in tags)
            {
                predicat = predicat.Or(q => q.Tags.Contains(tag).Boost(1.5f));
            }

            queryable = queryable.Where(predicat);

            var results = queryable.GetResults();
        }

Azure Search Config

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
      <contentSearch>
          <indexConfigurations>
            <defaultCloudIndexConfiguration type="Sitecore.ContentSearch.Azure.CloudIndexConfiguration, Sitecore.ContentSearch.Azure">
                  <fieldMap type="Sitecore.ContentSearch.Azure.FieldMaps.CloudFieldMap, Sitecore.ContentSearch.Azure">
                      <fieldNames hint="raw:AddFieldByFieldName">
                        <field fieldName="tags" 
                               storageType="YES" 
                               indexType="UNTOKENIZED" 
                               vectorType="NO" 
                               type="System.Collections.Generic.List`1[[System.String, mscorlib]]" 
                               boost="1f" 
                               settingType="Sitecore.ContentSearch.Azure.CloudSearchFieldConfiguration, Sitecore.ContentSearch.Azure" />
                      </fieldNames>
                  </fieldMap>
              </defaultCloudIndexConfiguration>
          </indexConfigurations>
      </contentSearch>      
  </sitecore>
</configuration>

Lucene Search Config

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
      <contentSearch>
          <indexConfigurations>
              <defaultLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
                  <fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
                      <fieldNames hint="raw:AddFieldByFieldName">
                        <field fieldName="tags" 
                               storageType="YES" 
                               indexType="UNTOKENIZED" 
                               vectorType="NO" 
                               type="System.String" 
                               boost="1f"
                               settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                      </fieldNames>
                  </fieldMap>
              </defaultLuceneIndexConfiguration>
          </indexConfigurations>
      </contentSearch>      
  </sitecore>
</configuration>

I'm very confused as to why boosting doesn't work, even though the search code used is the same and as far as I'm aware both configs are more or less the same so does anyone know why Azure search boosting doesn't work

Any help would be appreciated thanks :)

1
  • try to increase boosting value to 10.0f
    – Vlad
    Commented Nov 19, 2018 at 13:28

2 Answers 2

2

I think the issue here is using .Contains() rather than .Equals().

I also wrote code to use Contains at first, as this makes the most sense to a human and used to work as expected with Lucene/Solr. Unfortunately, the Azure Search provider doesn't seem to provide identical functionality.

It is worth noting that when using the Azure Search provider the Equals method doesn't insist on the search term and the target field being identical; in the version of Sitecore I tested on (v9 initial), Equals behaves like you'd expect Contains to work.

I've done a before and after test, and the results returned remain consistent but the order is different when using Equals and a boost.

1

I found that choosing boost values which were powers of two (4, 9, 16, 25, 36...) produced the expected result ordering. I first tried having a linear set of boost values (2, 4, 6, 8, 10...) and that had almost no discernable effect on result ordering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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