Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't require searchable facets for popular categories #31

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

sbellone
Copy link
Collaborator

@sbellone sbellone commented Oct 7, 2024

The getAlgoliaFacets function requires the targeted facet to be searchable.
Since it's not a requirement for our SFRA cartridge, if people try the demo on their existing index, they would get the following error and the search results wouldn't appear:

"Cannot search in __primary_category.1 attribute, you need to add searchable(__primary_category.1) to attributesForFaceting."

Algolia has a way to get the facets and their count that doesn't require to have searchable facets: https://www.algolia.com/doc/guides/managing-results/refine-results/faceting/#retrieving-facets
This PR uses this method to retrieve the facets.

The results object contains the following object:

[{
  "facets": {
    "__primary_category.1": {
      "Mens > Clothing": 490,
      "Womens > Accessories": 91,
      // ...
    }
  },
  // ...
}]

The transformResponse function transform it into a sorted array of { label: int, count: int } objects, like the getAlgoliaFacets was doing.


SFCC-388

@sbellone sbellone merged commit 0debc6d into develop Oct 14, 2024
2 checks passed
@sbellone sbellone deleted the fix/dont-require-searchable-facets branch October 14, 2024 08:04
sbellone added a commit that referenced this pull request Oct 14, 2024
If you currently run the demo without Recommend, the popup doesn't
display because the recommend index isn't found.

Since Recommend is complex to setup, I propose to not rely on it by
default, so anyone can run the demo more easily.

This PR uses the same approach than #31 to fetch the most popular
`brand` facets from the search results.
I'm also leaving the recommend code commented to give pointer about how
to integrate Recommend.

Note: since our demo index is not fully trained, this approach actually
works better:
- the current demo displays `Lacy-D`, `Arlene` and `Lacy-S`
- locally I now get `Apple`, `Sony`, `Lacy-D` and `Garmin`

---
SFCC-390
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants