Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely Search & Navigation
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Introduction

By default search results are sorted according to score (relevance). In some scenarios we want to boost the score of hits based on certain criteria. Searching using unified weights is one of the ways to achieve this.

Administrators are able to set the weight of the different properties on the Unified Search object, like title, content, summary or attached document content. The default property weight is 1 and does not affect default results sorting. A value higher than 1 boosts the hit if the information is found in corresponding property. A weight value smaller than 1 makes the hit less important.

Search using weight values

The UnifiedSearchFor extension method for IClient can be found in the EPiServer.Find namespace. With the new EPiServer Find index, this method enables search using administrator-defined weight values. For example earching for "Beethoven" with weights:

C#
var results = client.UnifiedSearchFor("Beethoven").GetResult();

Searching for "Beethoven" with weights and Swedish applied for stemming:

C#
var results = client.UnifiedSearchFor("Beethoven", Language.Swedish).GetResult();

In addition, there are UnifiedSearchFor extension methods for IClient in the EPiServer.Find.Cms namespace, that takes search query as a parameter. The language used for stemming is selected automatically based on EPiServer.Globalization.ContentLanguage.PreferredCulture and configured culture for stemming mappings in the episerver.find section in app.config/web.config (if defined). Searching for "Beethoven" with weights and automatically selected stemming language:

C#
var results = client.UnifiedSearchFor("Beethoven").GetResult();

Another option is to use UsingUnifiedWeights extension methods for IQueriedSearch from EPiServer.Find namespace. Searching for "Beethoven" with weights and English applied for stemming:

C#
var result = client.UnifiedSearch(Language.English).For("Beethoven").UsingUnifiedWeights().GetResult();

There is a UsingUnifiedWeights extension method that takes UnifiedWeightsValues parameter, and allowing for specifying weights that should be used when searching. Searching for "Beethoven" with specific weights and English applied for stemming:

C#
var weights = new UnifiedWeightsValues() 
    { 
        SearchTitle = 2.0, 
        SearchText = 1.5, 
        SearchSummary = 1.0, 
        SearchAttachment = 0.5 
    };

var result = client.UnifiedSearch(Language.English).For("Beethoven").UsingUnifiedWeights(weights).GetResult();

Specified weights means that hits where "Beethoven" appear in the title are the most important and should be displayed in the first place. Hits that contain "Beethoven" in the body should also be boosted, whereas having "Beethoven" in the content of a related document makes the hit less important.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Jun 10, 2014

Recommended reading