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(helper): correctly set isRefined for hierarchical facet values with trailing spaces #6059

Merged
merged 5 commits into from Feb 20, 2024

Conversation

dhayab
Copy link
Member

@dhayab dhayab commented Feb 16, 2024

Summary

Hierarchical facet values that have a trailing space are not correctly flagged with isRefined: true during the generation of the hierarchical tree. This is because its path part is compared to its name, which is trimmed by another part of the code.

This PR ensures the part is also trimmed when comparing it to the name.

Result

Hierarchical facet values that are refined are marked as so by the returned data from getFacetValues().

Derived from CR-5241

@dhayab dhayab requested review from a team, sarahdayan and aymeric-giraudet and removed request for a team February 16, 2024 10:20
Copy link

codesandbox-ci bot commented Feb 16, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a53bae3:

Sandbox Source
react-instantsearch-app Configuration
example-react-instantsearch-default-theme Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-vue-instantsearch-default-theme Configuration

@Haroenv
Copy link
Contributor

Haroenv commented Feb 16, 2024

How does this happen? can it happen for non-hierarchical facets too? seems a little odd for the place of the normalisation of the facet value to be.

@dhayab
Copy link
Member Author

dhayab commented Feb 16, 2024

How does this happen? can it happen for non-hierarchical facets too? seems a little odd for the place of the normalisation of the facet value to be.

This happens because the deep equality check fails, as the current refinement part is compared against a reference that has been trimmed here: https://github.com/algolia/instantsearch/blob/master/packages/algoliasearch-helper/src/SearchResults/generate-hierarchical-tree.js#L192.

Conjunctive / disjunctive facets go through another method to set their isRefined flag which works as expected.

I can't see anywhere else to normalise the variable for this check, this is very specific to the hierarchical menu generation.

@Haroenv
Copy link
Contributor

Haroenv commented Feb 16, 2024

Thanks, but I meant: how do you get an untrimmed facet value?

@dhayab
Copy link
Member Author

dhayab commented Feb 16, 2024

Ah! This was discovered in a customer's dataset, one of their facet values had a trailing space.

@dhayab
Copy link
Member Author

dhayab commented Feb 20, 2024

@Haroenv are you satisfied with the changes, can I go ahead and merge it?

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's a valid reason for this to exist, why not, but I would overall suggest to fix indexing first

@dhayab dhayab merged commit a12e567 into master Feb 20, 2024
12 checks passed
@dhayab dhayab deleted the fix/hierarchical-refined-trailing-space branch February 20, 2024 15:36
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.

None yet

3 participants