Hide menu Last updated: Oct 31 2016
Area: Episerver Find Applies to versions: 12 and higher
Other versions:

Boosting with weights

Episerver Find sorts search results by score (relevance) by default. In some scenarios, you can boost scores based on certain criteria by using Unified weights, as described in this topic.

How it works

In the Episerver Find admin view, administrators can set a relative weight of different properties (title, content, summary, or attached document content) via the Unified Search object. The default property weight, 1, does not affect the score. A weight above 1 boosts the score if the information is found in a corresponding property. A weight smaller than 1 reduces the score.

Search using weight values


The IClient UnifiedSearchFor extension method exists in the EPiServer.Find namespace. The method enables search using administrator-defined weight values. For example, searching for Beethoven with weights:

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

Searching for Beethoven with weights and Swedish applied for stemming:

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

In addition, UnifiedSearchFor extension methods for IClient (in the EPiServer.Find.Cms namespace) take a search query as a parameter. The language used for stemming is selected automatically (based on EPiServer.Globalization.ContentLanguage.PreferredCulture), and the culture for stemming mappings is defined in the episerver.find section in app.config/web.config. The following sample searches for Beethoven with weights and the automatically-selected stemming language.

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


Another option is to use the UsingUnifiedWeights extension method for IQueriedSearch from EPiServer.Find namespace. The following example shows how to search for Beethoven with weights and English applied for stemming:

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

The UsingUnifiedWeights extension method takes a UnifiedWeightsValues parameter, which lets you specify weights when searching. Here is a sample of searching for Beethoven with specific weights and English applied for stemming:

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();

In the above sample, hits for which Beethoven appears in the title are the most important and should appear at the top of search results. Hits that contain Beethoven in the body are also boosted, but having Beethoven in an attached document's content is less important.