Refining ESHOPMAN Storefront Search: Addressing Inaccurate Facet Statistics

Understanding ESHOPMAN's Search Facet Accuracy

At Move My Store, we understand that precise search functionality is paramount for any successful e-commerce storefront, especially within a headless commerce setup like ESHOPMAN. Accurate product filtering and statistics directly impact customer experience and conversion rates on HubSpot CMS-powered storefronts. Recently, our ESHOPMAN community identified and discussed a critical issue within the ESHOPMAN

search-postgres
module concerning the accuracy of 'stats' facets.

This insight delves into the problem, its technical roots, and the proposed solutions, offering valuable knowledge for ESHOPMAN developers and merchants.

The Challenge: Misleading Storefront Facet Statistics

The core of the issue lies in how ESHOPMAN's

search-postgres
module calculates and presents 'stats' facets for numeric fields. When some or all matched documents lack a value for a specific numeric field (e.g., product width), the facet results can be misleading:

  • Incorrect Min/Max Values: If none of the matched documents have a value for the field, the facet incorrectly returns
    min: 0, max: 0
    . This can be confused with an actual range from 0 to 0, rather than indicating the absence of values.
  • Inaccurate Document Count: The
    count
    for a stats facet uses
    COUNT(*)
    , which tallies every matched document, regardless of whether that document actually possesses a value for the field. This means the count doesn't reflect the number of items truly contributing to the statistical range.

For ESHOPMAN storefronts deployed via HubSpot CMS, this can lead to confusing filter options and inaccurate data presentation to customers.

Technical Deep Dive: Uncovering the Root Cause

The ESHOPMAN community's investigation pinpointed two primary areas within the ESHOPMAN

search-postgres
module's utility files, specifically in
facets.ts
, that contribute to this behavior:

  1. COUNT(*)
    in SQL Queries:
    The underlying SQL query for stats facets uses
    COUNT(*)
    instead of
    COUNT(expr)
    . The former counts all rows, while the latter would correctly count only rows where the expression (the field value) is not NULL. The problematic query snippet is:
    SELECT
      MIN(expr) AS min,
      MAX(expr) AS max,
      AVG(expr) AS avg,
      SUM(expr) AS sum,
      COUNT(*)::int AS count
    FROM ... WHERE ...
  2. NULL Handling for Min/Max: The result mapping logic explicitly converts NULL
    min
    and
    max
    values to
    0
    using the nullish coalescing operator (
    ?? 0
    ). In contrast,
    avg
    and
    sum
    correctly map NULLs to
    undefined
    , which is the expected behavior when no values exist.

The ESHOPMAN Community's Solution Path

A comprehensive fix, as discussed by the ESHOPMAN community, involves:

  • Correcting the Count: Modifying the SQL query to use
    COUNT(expr)::int AS count
    to accurately reflect documents with actual field values.
  • Refining Min/Max Mapping: Ensuring that NULL
    min
    and
    max
    values are mapped to
    undefined
    , aligning with the behavior of
    avg
    and
    sum
    .
  • Admin API Type Update: This fix also necessitates an update to the ESHOPMAN Admin API's
    SearchFacetResult
    type definition, making
    min
    and
    max
    optional properties to correctly represent scenarios where no values are present. This is a crucial change for developers interacting with the ESHOPMAN Admin API for storefront management.

Several dedicated ESHOPMAN community members have already expressed interest in contributing to this fix, highlighting the collaborative spirit driving ESHOPMAN's development.

Conclusion

This detailed insight into the

search-postgres
module's facet behavior underscores ESHOPMAN's commitment to delivering a robust and accurate headless commerce experience. Addressing these nuances ensures that ESHOPMAN merchants can provide their customers with precise and intuitive search and filtering capabilities on their HubSpot CMS storefronts. Stay tuned for updates on this resolution, which will further enhance the ESHOPMAN platform's capabilities.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools