A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Rajveer Singh
Jul 1, 2025
  495
(0 votes)

Boosting by published date with Relevance

Goal: To ensure that the latest published or last updated content is ranked higher in your search results, you can modify your query to include a boost based on recency. This typically involves boosting content based on a date field such as PublishedDate or LastUpdated.

Here’s how you can update your query to prioritize recent content while still considering relevance:

var result = query.ApplyBestBets()
    .BoostMatching(x => ((IContent)x).SearchTitle().MatchCaseInsensitive(contentFilter.SearchQuery), 1.5)
    .OrderByDescending(x => ((IContent)x).LastUpdated) // Boost by recency
    .Take(pageSize)
    .Skip((pageNo - 1) * pageSize)
    .StaticallyCacheFor(TimeSpan.FromSeconds(CacheSpan))
    .GetResult(hitSpec);

Explanation:

  • OrderByDescending(x => ((IContent)x).LastUpdated) ensures that the most recently updated content appears first.
  • If you want to balance relevance and recency, you might consider a custom scoring function or a composite boost that combines both.

 

------------

 

Also, we can implementing a more advanced scoring strategy that balances relevance and freshness as below:

To implement a balanced scoring strategy that considers both relevance and recency, you can use a custom boost function. This approach allows you to:

  • Boost content that matches the search query (relevance).
  • Boost content that is recently published or updated (recency).
  • Combine both into a composite score.

Here’s how you can update your query using a custom boost expression:

var result = query.ApplyBestBets()
    .BoostMatching(x => ((IContent)x).SearchTitle().MatchCaseInsensitive(contentFilter.SearchQuery), 1.5)
    .OrderByDescending(x => 
        ((IContent)x).SearchTitle().MatchCaseInsensitive(contentFilter.SearchQuery) ? 1 : 0 + 
        GetRecencyScore(((IContent)x).LastUpdated)
    )
    .Take(pageSize)
    .Skip((pageNo - 1) * pageSize)
    .StaticallyCacheFor(TimeSpan.FromSeconds(CacheSpan))
    .GetResult(hitSpec);

You’ll need to define GetRecencyScore like this:

private double GetRecencyScore(DateTime lastUpdated)
{
    var daysOld = (DateTime.UtcNow - lastUpdated).TotalDays;

    // Example scoring: newer content gets higher score
    if (daysOld <= 1) return 1.0;
    if (daysOld <= 7) return 0.8;
    if (daysOld <= 30) return 0.5;
    if (daysOld <= 90) return 0.3;
    return 0.1;
}

Why this works:

  • It gives a higher score to recent content, but still considers query match.
  • You can tune the weights in GetRecencyScore to fit your needs.




Jul 01, 2025

Comments

Please login to comment.
Latest blogs
Building simple Opal tools for product search and content creation

Optimizely Opal tools make it easy for AI agents to call your APIs – in this post we’ll build a small ASP.NET host that exposes two of them: one fo...

Pär Wissmark | Dec 13, 2025 |

CMS Audiences - check all usage

Sometimes you want to check if an Audience from your CMS (former Visitor Group) has been used by which page(and which version of that page) Then yo...

Tuan Anh Hoang | Dec 12, 2025

Data Imports in Optimizely: Part 2 - Query data efficiently

One of the more time consuming parts of an import is looking up data to update. Naively, it is possible to use the PageCriteriaQueryService to quer...

Matt FitzGerald-Chamberlain | Dec 11, 2025 |

Beginner's Guide for Optimizely Backend Developers

Developing with Optimizely (formerly Episerver) requires more than just technical know‑how. It’s about respecting the editor’s perspective, ensurin...

MilosR | Dec 10, 2025