Boost with weights
Optimizely Search & Navigation 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.
In the Optimizely Search & Navigation admin view, administrators can set a relative weight of different properties (title, content, summary, or attached document content) with 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 in a corresponding property. A weight smaller than 1 reduces the score.
UnifiedSearchFor weight value
The IClient
UnifiedSearchFor
extension method is in the EPiServer.Find
namespace that 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();
UsingUnifiedWeights weight value
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 display at the top of search results. It also boosts hits that contain Beethoven in the body, but having Beethoven in an attached document's content is less important.
Updated 5 months ago