Don't miss out Virtual Happy Hour this Friday (April 26).

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 

By default, search results are sorted by score (relevance). In some scenarios, you want to boost scores based on certain criteria. Unified weights help you do this.

In the EPiServer 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

UnifiedSearchFor

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:

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, 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.

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

UsingUnifiedWeights

Another option is to use the UsingUnifiedWeights extension method for IQueriedSearch from EPiServer.Find namespace. Here is a sample of searching for "Beethoven" with weights and English applied for stemming:

C#
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:

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

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.

Note: EPiServer administrators can adjust the relative weight of title, content, summary, or attached document content in the Find administrative interface.

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

Last updated: Sep 21, 2015

Recommended reading