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 Jun 14, 2021
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 Jun 16, 2021
@Haroenv Haroenv requested review from a team, tkrugg and francoischalifour and removed request for a team Jun 16, 2021
Copy link
Contributor

@tkrugg tkrugg left a comment

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 issue 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.js#4784
- algolia/algoliasearch-helper-js#822
Haroenv added a commit to algolia/react-instantsearch that referenced this issue 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.js#4784
- algolia/algoliasearch-helper-js#822
@Haroenv Haroenv requested a review from tkrugg Jun 29, 2021
Haroenv added a commit to algolia/react-instantsearch that referenced this issue 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.js#4784
- algolia/algoliasearch-helper-js#822
Haroenv added a commit to algolia/react-instantsearch that referenced this issue 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.js#4784
- algolia/algoliasearch-helper-js#822
@Haroenv Haroenv requested review from tkrugg and eunjae-lee Jul 5, 2021
${true} | ${undefined} | ${resultsViaFacetOrdering}
${false} | ${undefined} | ${resultsViaSortBy}
${true} | ${['isRefined']} | ${resultsViaSortBy}
${false} | ${['isRefined']} | ${resultsViaSortBy}
Copy link
Contributor

@tkrugg tkrugg Jul 5, 2021

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

@Haroenv Haroenv Jul 5, 2021

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

tkrugg
tkrugg approved these changes Jul 5, 2021
Copy link
Contributor

@tkrugg tkrugg left a comment

Great work! 👍

@Haroenv Haroenv merged commit 9e9d839 into master Jul 5, 2021
13 checks passed
@Haroenv Haroenv deleted the feat/facetOrdering-values branch Jul 5, 2021
Haroenv added a commit to algolia/react-instantsearch that referenced this issue 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.js#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.

None yet

4 participants