Table of contents :

How to Rank Content by Popularity

100-days-of-algolia-032

Table of contents :

Popularity ranking is useful when shoppers want to discover what other customers buy most often, rather than finding a product that matches a highly specific query. In Algolia, the usual implementation is to index a numeric popularity signal and use that signal in customRanking.

Choose a popularity signal

A popularity value should represent meaningful customer interest. For a WooCommerce store, possible inputs include completed orders, units sold, product detail views, add-to-cart events, or a weighted combination of these signals.

A simple lifetime sales count is easy to implement, but it tends to favor older products permanently. A time-bounded or decayed metric is usually more useful:

popularity = (orders_30d * 10) + (add_to_carts_30d * 3) + (views_30d * 0.1)

Calculate this value in the data pipeline rather than during a search request. Store the final result as a numeric Algolia attribute, for example:

{
  "objectID": "4821",
  "name": "Waterproof Hiking Jacket",
  "categories": ["Outdoor Clothing", "Jackets"],
  "price": 129.99,
  "popularity": 864,
  "orders_30d": 72,
  "in_stock": true
}

Keep the raw counters when they are useful for reporting, but use one normalized field for ranking. This makes index configuration simpler and allows the scoring formula to change without changing the search implementation.

Configure popularity as custom ranking

Set the popularity attribute as a descending custom ranking criterion:

{
  "customRanking": [
    "desc(popularity)"
  ]
}

In a standard Algolia search index, custom ranking is applied after the main textual relevance criteria. A query that matches a product precisely can therefore remain ahead of a more popular product with a weak match. Popularity acts as a tie-breaker within results that are otherwise similarly relevant.

This is generally preferable to replacing relevance with a popularity score. A product with thousands of historical views should not outrank a highly relevant product simply because the customer used a specific search phrase.

Use a replica for a dedicated popular sort

If the store needs both relevance-ranked search and a separate “Most Popular” sort, use a replica rather than changing the primary index for every request. Configure a replica with popularity as its ranking criterion, then select that index when the customer chooses the sort option.

A common index arrangement is:

  • products for the default relevance ranking.
  • products_popularity_desc for the most-popular sort.
  • products_price_asc and products_price_desc for price sorting, when required.

The application can map a user-facing sort label to an approved index name:

const indexes = {
  relevance: "products",
  popular: "products_popularity_desc",
  priceAsc: "products_price_asc"
};

const indexName = indexes[selectedSort] || indexes.relevance;
const index = searchClient.initIndex(indexName);

Do not accept an arbitrary index name directly from a request parameter. Maintain an allowlist so visitors cannot use the sort control to query unintended indexes.

Make popularity safe for product availability

Popularity should not cause unavailable products to dominate the result set. Index an availability attribute and apply an appropriate filter:

filters: "in_stock:true AND catalog_visible:true"

For variable products, decide whether popularity belongs to the parent product or to each variation. Parent-level ranking is usually clearer for category pages, while variation-level ranking can be useful when size, color, or other attributes are independently searchable.

Also account for products with no history. A new product with a missing popularity value may sort unpredictably. Set a default of zero during indexing and consider a controlled launch boost for products that meet business requirements, such as having inventory, a complete catalog record, or an active promotion.

Normalize and decay the score

Raw counts can create several ranking problems:

  • Large stores may produce values that are difficult to compare across categories.
  • Older products can accumulate permanent advantages.
  • One viral event can dominate the ranking long after interest has declined.
  • High-traffic categories can overwhelm lower-traffic categories.

A rolling window, logarithmic transformation, or time-decay calculation can reduce these effects. For example:

score = log1p(orders_30d) * 10 + log1p(add_to_carts_30d) * 3 + log1p(views_30d)

Test the formula against real category data. The goal is not to maximize the numeric score; it is to produce a stable ordering that reflects useful customer behavior.

Update records without rebuilding the entire catalog

Popularity changes more frequently than product names, descriptions, or taxonomies. Use partial record updates for the ranking fields instead of exporting the complete catalog for every metric change:

await index.partialUpdateObjects([
  {
    objectID: "4821",
    popularity: 912,
    orders_30d: 78
  }
], {
  createIfNotExists: false
});

Batch updates from a scheduled WooCommerce job, order-processing event, or analytics pipeline. Avoid sending one update for every page view if traffic is high. Aggregate events over a short interval and update Algolia in batches to reduce indexing overhead.

When an order is canceled or refunded, ensure that the source metrics are corrected by the next aggregation run. Ranking data should be derived from a repeatable process rather than only from irreversible increments.

Distinguish popularity sorting from dynamic re-ranking

A fixed customRanking value is controlled by the attributes in the indexed record. Algolia also supports Dynamic Re-Ranking, which can use behavioral signals such as clicks and conversions to adjust results for eligible searches and configurations. These are different mechanisms.

Use custom ranking when the agency needs an explicit, auditable business metric such as orders in the last 30 days. Consider Dynamic Re-Ranking when sufficient search analytics and conversion events are available and the team wants Algolia to optimize ordering based on observed behavior. In either case, verify that click and conversion events are associated with the correct application user, index, query, and object IDs.

Measure the result in WooCommerce

Compare the popularity sort with the default relevance experience using metrics that matter to the store:

  • Search-to-product-click rate.
  • Add-to-cart rate from search and category pages.
  • Conversion rate and revenue per search session.
  • Zero-result and refinement usage.
  • Performance by category, device, and query type.

Review the results separately for broad discovery queries, specific product queries, and category browsing. A popularity sort may work well for an empty-query product listing but perform poorly for an exact model-number search. Keep the relevance index available and expose popularity as an intentional sort or browse mode rather than applying it indiscriminately.

Trending posts
You might also like