Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

feat(getFacetValues): process facetOrdering #822

Merged
merged 5 commits into from
Jun 14, 2021

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Jun 9, 2021

This adds support for reading from facetOrdering in getFacetValues. It's applied by default if no sortBy is given, but can be forced (or disabled) by facetOrdering in opts.

results.getFacetValues('brand'); // facet ordering
results.getFacetValues('brand', { }); // facet ordering
results.getFacetValues('brand', { sortBy: ['isRefined:asc'] }); // no facet ordering
results.getFacetValues('brand', { sortBy: ['isRefined:asc'], facetOrdering: false }); // no facet ordering
results.getFacetValues('brand', { sortBy: ['isRefined:asc'], facetOrdering: true }); // facet ordering

DX-2075

src/SearchResults/index.js Outdated Show resolved Hide resolved
@Haroenv Haroenv force-pushed the feat/facet-value-ordering branch from e464183 to a620e5b Compare June 9, 2021 16:24
@Haroenv Haroenv changed the base branch from feat/ts-rendering-content to develop June 9, 2021 16:24
@Haroenv Haroenv requested review from a team, tkrugg and shortcuts and removed request for a team June 10, 2021 07:25
src/SearchResults/index.js Outdated Show resolved Hide resolved
src/SearchResults/index.js Outdated Show resolved Hide resolved
@Haroenv Haroenv requested a review from shortcuts June 10, 2021 12:26
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

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

Great feature!

src/SearchResults/index.js Outdated Show resolved Hide resolved
src/SearchResults/index.js Show resolved Hide resolved
src/SearchResults/index.js Outdated Show resolved Hide resolved
Comment on lines +736 to +738
} else {
ordering = [['count'], ['desc']];
}
Copy link
Member

Choose a reason for hiding this comment

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

Making sure: we decide to fallback to sorting by count and not throwing if the provided order is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's something that's a bit blurry at the moment, the spec mentions falling back to sortFacetValuesBy, but I can't retrieve that in the result-side, so I think falling back to just count by default is reasonable.

Alternatively we could make sortRemainingBy required in the dashboard possibly. What did you pick @VladislavFitz?

Choose a reason for hiding this comment

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

required in the dashboard

What do you mean? Make the engine always return renderingContent even if it's not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is about the key sortRemainingBy, what do you sort by if the key isn't given?

Choose a reason for hiding this comment

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

Sort by count by default sounds good to me 👍

src/SearchResults/index.js Outdated Show resolved Hide resolved
src/SearchResults/index.js Show resolved Hide resolved
test/spec/SearchResults/getFacetValues-facetOrdering.js Outdated Show resolved Hide resolved
Comment on lines +164 to +167
var facetValues = result.getFacetValues('brand', {
sortBy: ['name:desc'],
facetOrdering: true
});
Copy link
Member

Choose a reason for hiding this comment

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

That behavior is getting confusing. Shouldn't we throw instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is needed for the hierarchical menu and menu widgets, they have a sortBy which isn't the default one, but still need to take facet ordering in account.

Copy link
Member

Choose a reason for hiding this comment

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

IIUC that's an internal constraint but that constraint leaks in the public API, which is annoying—but I get the point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see how others might want both a non-default sortBy, but still try to use facetOrdering if it's given

@Haroenv Haroenv merged commit 8c7ff44 into develop Jun 14, 2021
@Haroenv Haroenv deleted the feat/facet-value-ordering branch June 14, 2021 08:18
Haroenv added a commit that referenced this pull request Jun 14, 2021
 * feat(getFacetValues): process facetOrdering (#822) 8c7ff44
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 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 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 to algolia/instantsearch 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
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
…lper-js#822)

* feat(getFacetValues): process facetOrdering

DX-2075

* fix: behave correctly on facetOrdering: false

* pinned -> ordered

* better description

* simplify tests & code slightly
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants