Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 120 posts 448 karma points
    Feb 11, 2022 @ 08:35
    Tom
    0

    Examine and boosting by frequency of a word in a field

    Hi

    Does anyone know how to boost the score of a result, base on the number of times a certain term/word occurs in a certain field?

    So if we search "bottle" and "bottle" occurs 30 times in the field "bodyText" in a document, I would like it to boost that document by 0.05f per occurrence.

                var fieldList = new List<string> { "seoTitle", "header", "seoMetaDescription", "seoMetaKeywords", "bodyText", "bodyContent", "leadText" }
    
                if (ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
                {
                    var query = "";
                    foreach (var field in model.SearchFields)
                    {
                        foreach (var term in model.SearchTerms)
                        {
                            if (field == "bodyText" || field == "bodyContent")
                            {
                                query += "(" + field + ": " + term.ToLower() + "^0.2)";
    
                            }
                            else
                            {
                                query += "(" + field + ": " + term.ToLower() + ")";
                            }
                        }
    
                    }
    
                    var queryContent = index.GetSearcher().CreateQuery().NativeQuery(query);
                    var resultContent = Current.PublishedContentQuery.Search(query: queryContent);
                }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies