Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

Episerver find use Boosting with weights and take 3 items sometime return different results

$
0
0

Hi,

I don't know why Episerver find used Boosting with weights and then take 3 items sometime return different results. I think it should order by weights and result should be consistent

Example:

var itypesearch = ContentDataQueryHandler.Instance.Create()
.Search<Product>()
.ForWithWildcards(searchText, (x => x.Code, 4), (x => x.DisplayName, 3), (x => x.ProductType, 2), (x => x.Brand, 1.5))
.FilterForVisitor(language.Name).ApplyBestBets().UsingAutoBoost().Take(3)
 public static ITypeSearch<T> ForWithWildcards<T>(
           this ITypeSearch<T> search,
           string query,
           params (Expression<Func<T, string>>, double?)[] fieldSelectors)
        {
            return search
                    .For(query)
                    .InFields(fieldSelectors.Select(x => x.Item1).ToArray())
                    .WildcardSearch(query, fieldSelectors);
        }
        public static ITypeSearch<T> WildcardSearch<T>(this ITypeSearch<T> search,
            string query, params (Expression<Func<T, string>>, double?)[] fieldSelectors)
        {
            if (string.IsNullOrWhiteSpace(query))
                return search;
            query = query.ToLowerInvariant().Replace('\'', '*');
            var words = query.Split(new[] { "" }, StringSplitOptions.RemoveEmptyEntries)
                .Select(WrapInAsterisks)
                .ToList();
            var wildcardQueries = new List<WildcardQuery>();
            foreach (var fieldSelector in fieldSelectors)
            {
                string fieldName = search.Client.Conventions
                    .FieldNameConvention
                    .GetFieldNameForAnalyzed(fieldSelector.Item1);
                foreach (var word in words)
                {
                    wildcardQueries.Add(new WildcardQuery(fieldName, word)
                    {
                        Boost = fieldSelector.Item2
                    });
                }
            }
            return new Search<T, WildcardQuery>(search, context =>
            {
                var boolQuery = new BoolQuery();
                if (context.RequestBody.Query != null)
                {
                    boolQuery.Should.Add(context.RequestBody.Query);
                }
                foreach (var wildcardQuery in wildcardQueries)
                {
                    boolQuery.Should.Add(wildcardQuery);
                }
                boolQuery.MinimumNumberShouldMatch = 1;
                context.RequestBody.Query = boolQuery;
            });
        }

Can somebody clarify to this question?

Regards,

Thang Le


Viewing all articles
Browse latest Browse all 8020

Trending Articles