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

feat(facets): apply result from facet ordering #4784

Merged
merged 7 commits into from
Jul 5, 2021

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Jun 16, 2021

passes facetOrderign to refinementList, menu, hierarchicalMenu which will read facet ordering from the results if available and no sortBy is given, but fall back to sortBy if no facetOrdering is available.

The option facetOrdering defaults to true if no sortBy is given, to make it apply out of the box.

references:

Haroenv added 2 commits June 14, 2021 18:10
This adds a new option "facetOrdering" (boolean) to refinementList, menu, hierarchicalMenu which will read facet ordering from the results if available, but fall back to sortBy if no facetOrdering is available.

The option facetOrdering defaults to `true` if no sortBy is given, to make it apply out of the box.

references:
- NLP-110
- [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 16, 2021

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 53b3745:

Sandbox Source
InstantSearch.js Configuration

@Haroenv Haroenv marked this pull request as ready for review June 16, 2021 10:57
@Haroenv Haroenv requested review from a team, tkrugg and francoischalifour and removed request for a team June 16, 2021 10:57
Copy link
Contributor

@tkrugg tkrugg left a comment

Choose a reason for hiding this comment

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

Nice! so many applications for this feature!
I left 1 comment and 1 question :)

Haroenv added a commit to algolia/react-instantsearch that referenced this pull request Jun 25, 2021
…mentList & HierarchicalMenu

If `facetOrdering` is enabled (the default behaviour), before the default sortBy is used, the result from renderingContent.facetOrdering.values is first checked. If that's present, it will be used to sort the items.

You can still change that ordering afterwards with the existing transformItems, so if you are sorting in transformItems, you actually override the sorting done by facet ordering, and won't see the effect. To use facetOrdering, you thus need to remove any sorting done in transformItems.

If there is a facetOrdering present in the index, but you don't want to use it for a certain widget, you need to explicitly pass `facetOrdering: false` to the widget or connector

References:
- [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
- algolia/instantsearch#4784
- algolia/algoliasearch-helper-js#822
Haroenv added a commit to algolia/react-instantsearch that referenced this pull request Jun 28, 2021
…mentList & HierarchicalMenu

If `facetOrdering` is enabled (the default behaviour), before the default sortBy is used, the result from renderingContent.facetOrdering.values is first checked. If that's present, it will be used to sort the items.

You can still change that ordering afterwards with the existing transformItems, so if you are sorting in transformItems, you actually override the sorting done by facet ordering, and won't see the effect. To use facetOrdering, you thus need to remove any sorting done in transformItems.

If there is a facetOrdering present in the index, but you don't want to use it for a certain widget, you need to explicitly pass `facetOrdering: false` to the widget or connector

References:
- [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
- algolia/instantsearch#4784
- algolia/algoliasearch-helper-js#822
@Haroenv Haroenv requested a review from tkrugg June 29, 2021 18:57
Haroenv added a commit to algolia/react-instantsearch that referenced this pull request Jun 30, 2021
…mentList & HierarchicalMenu

If `facetOrdering` is enabled (the default behaviour), before the default sortBy is used, the result from renderingContent.facetOrdering.values is first checked. If that's present, it will be used to sort the items.

You can still change that ordering afterwards with the existing transformItems, so if you are sorting in transformItems, you actually override the sorting done by facet ordering, and won't see the effect. To use facetOrdering, you thus need to remove any sorting done in transformItems.

If there is a facetOrdering present in the index, but you don't want to use it for a certain widget, you need to explicitly pass `facetOrdering: false` to the widget or connector

References:
- [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
- algolia/instantsearch#4784
- algolia/algoliasearch-helper-js#822
Haroenv added a commit to algolia/react-instantsearch that referenced this pull request Jul 2, 2021
…mentList & HierarchicalMenu

If `facetOrdering` is enabled (the default behaviour), before the default sortBy is used, the result from renderingContent.facetOrdering.values is first checked. If that's present, it will be used to sort the items.

You can still change that ordering afterwards with the existing transformItems, so if you are sorting in transformItems, you actually override the sorting done by facet ordering, and won't see the effect. To use facetOrdering, you thus need to remove any sorting done in transformItems.

If there is a facetOrdering present in the index, but you don't want to use it for a certain widget, you need to explicitly pass `facetOrdering: false` to the widget or connector

References:
- [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
- algolia/instantsearch#4784
- algolia/algoliasearch-helper-js#822
@Haroenv Haroenv requested review from tkrugg and eunjae-lee July 5, 2021 11:48
${true} | ${undefined} | ${resultsViaFacetOrdering}
${false} | ${undefined} | ${resultsViaSortBy}
${true} | ${['isRefined']} | ${resultsViaSortBy}
${false} | ${['isRefined']} | ${resultsViaSortBy}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's be worth picking a sortBy input that yields a different result than the default value (same for connectMenu-test.ts and connectHierarhicalMenu-test.ts). Just having resultsViaSortByDefaultValue and resultsViaSortByIsRefined.

The rational: right now, I could (accidentally) change the implementation to ignore sortBy prop and this test would still pass.

Another test is still going to break, so I don't consider this a blocker, just a safer testing strategy. Not a blocker for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 but this result is already different than the one from from facet ordering, that's why only facetOrdering present in result + undefined sortBy uses the one from facet ordering

Copy link
Contributor

@tkrugg tkrugg left a comment

Choose a reason for hiding this comment

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

Great work! 👍

@Haroenv Haroenv merged commit 9e9d839 into master Jul 5, 2021
@Haroenv Haroenv deleted the feat/facetOrdering-values branch July 5, 2021 12:40
Haroenv added a commit to algolia/react-instantsearch that referenced this pull request Jul 5, 2021
…t & HierarchicalMenu (#3067)

* feat(facetOrdering): add a new option "facetOrdering" to Menu, RefinementList & HierarchicalMenu

If `facetOrdering` is enabled (the default behaviour), before the default sortBy is used, the result from renderingContent.facetOrdering.values is first checked. If that's present, it will be used to sort the items.

You can still change that ordering afterwards with the existing transformItems, so if you are sorting in transformItems, you actually override the sorting done by facet ordering, and won't see the effect. To use facetOrdering, you thus need to remove any sorting done in transformItems.

If there is a facetOrdering present in the index, but you don't want to use it for a certain widget, you need to explicitly pass `facetOrdering: false` to the widget or connector

References:
- [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
- algolia/instantsearch#4784
- algolia/algoliasearch-helper-js#822

* clarify
Haroenv added a commit that referenced this pull request Jan 4, 2023
…t & HierarchicalMenu (algolia/react-instantsearch#3067)

* feat(facetOrdering): add a new option "facetOrdering" to Menu, RefinementList & HierarchicalMenu

If `facetOrdering` is enabled (the default behaviour), before the default sortBy is used, the result from renderingContent.facetOrdering.values is first checked. If that's present, it will be used to sort the items.

You can still change that ordering afterwards with the existing transformItems, so if you are sorting in transformItems, you actually override the sorting done by facet ordering, and won't see the effect. To use facetOrdering, you thus need to remove any sorting done in transformItems.

If there is a facetOrdering present in the index, but you don't want to use it for a certain widget, you need to explicitly pass `facetOrdering: false` to the widget or connector

References:
- [RFC 45](https://github.com/algolia/instantsearch-rfcs/blob/master/accepted/flexible-facet-values.md)
- #4784
- algolia/algoliasearch-helper-js#822

* clarify
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.

4 participants