Try our conversational search powered by Generative AI!

Possible to boost with weights, without using unified search?

Vote:
 

A client complained that the search result was not changed when they set the weights in the Episerver Find admin view. 

If I get it right, those weights are only used when you do a UnifiedSearch (or UnifiedSearchFor). We are doing a .Search and GetContentResult, because we need the result as content.

Is there a way to keep the current funtionality and let the client set weight in admin mode?

I'm guessing that what I want to do is either

  • Boost with weights, without using UnifiedSearch
  • Or, simulate GetContentResult when using UnifiedSearch. But there doesn't seem to be a "content id" in the UnifiedSearchResults.

Or should I tell the client to ignore the weight setting in admin mode, and we set the boosting in code using .BostMatching?

Thanks for any advice!

 

#196930
Edited, Sep 17, 2018 15:35
Vote:
 

Hi. Seems like setting the weights via code is the only option if you are not using UnifiedSearch. That seems weird that the admin ui weights only work with UnifiedSearch. It would be very un-intuative, for instance, if you had different searchs that used both UnifiedSearch and .Search, and weights in the admin worked for one and not the other. Seems like it should work for both. 

#197068
Sep 20, 2018 18:29
Vote:
 

You should be able to fetch the weights set in the UI 

var unifiedWeightsQuery = 
SearchClient.Instance.NewCommand(context => new UnifiedWeightsCommand(context, SearchClient.Instance.DefaultIndex));

UnifiedWeightsItem weights = unifiedWeightsQuery.Execute().Hits.FirstOrDefault();

and apply them when specifying .InField(fieldName, relativeImportance)

#197093
Sep 21, 2018 10:49
Vote:
 

Usually, there is a sorting option that the user can use (Relevance, Date Asc/Desc). If one is set, the search result won't change because an orderBy has been applied and the result is no longer sorted by score. What we had to do was to end the query with the following extension

.ThenByScore() (Credit Henrik Lindström) https://gist.github.com/lindstromhenrik/9779858

To make sure that the score is actually taken into account after the inital sorting has been applied.

Then we created a custom "Boosting Settings" page type, where the editor can set the boosting multiplier for custom properties, and included that in the search query as well as ITypedSeach extension, something like

.AddCustomBoosting(searchRequest)

Then the function

public static ITypeSearch<T> AddCustomBoosting<T>(this ITypeSearch<T> query, SearchRequest searchRequest)
	where T : CustomPageType
{
  if (!string.IsNullOrEmpty(searchRequest.Query))
  {
    var queries = searchRequest.Query.Split(' ');
    foreach (var word in queries)
    {
      var cleanedWord = QueryEscaping.Quote(word);
      query = query
      .BoostMatching(x => x.DisplayName.AnyWordBeginsWith(cleanedWord), _siteSettingsPage.Content.BoostDisplayName)
      .BoostMatching(x => x.PageTitle.AnyWordBeginsWith(cleanedWord), _siteSettingsPage.Content.BoostPageTitle)
    }
  }
  return query;
}

Does this make sense?

#197100
Edited, Sep 21, 2018 14:31
Vote:
 

Thanks all of you! Hopefully I can make something out of this :-)

#197110
Sep 21, 2018 21:41
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.