Search: Fix aggregation ordering in search results#8100
Conversation
Elasticsearch doesn’t guarantee the order of returned Aggregations will match the input order, which leads to unexpected behavior when rendering the Aggregations in the Widget. Adds code to re-order the Aggregation results to match the ordering as passed to `Jetpack_Search::set_filters()`. Fixes #8096
|
Can't we have the code doing the display just use the aggregation name rather than relying on the order? |
|
The internals of the Search code combines the originally specified Aggregations into the Aggregation results array, so that there is a single array that contains both the settings as specified in It would be possible to re-sort them at the Widget level, but it's better having them in the 'expected' order (as defined by site developer) everywhere, so it's consistent regardless of how the module is used - in both the Widget, but also any custom code that builds upon |
|
Also I should give a demo of the problem. Say you do this: The Aggregations that get returned in the ES result aren't necessarily in the same order, so you could end up with an array like this: Then when the Widget renders, the ordering is 'off' and it's not possible to control the display order. |
gibrown
left a comment
There was a problem hiding this comment.
Ahh, I understand now. Thanks. LGTM
* Changelog 5.6: create base for changelog. * Update changelog with 5.5.1 info. * Changelog: add #7930 and #8238 * Changelog: add #8076 * Changelog: add #8100 * Changelog: add #8117 * Changelog: add #8141 * Changelog: add #8143 * Changelog: add #8147 * Changelog: add #8149 * Changelog: add #8153 * Changelog: add #8173 * Changelog: add #8184 * Changelog: add #8196 * Changelog: add #8199 * Changelog: add #8093 * Changelog: add #8171 * Changelog: add #8182 * Changelog: add #8202, #8222 * Changelog: add #8228 * Changelog: add #8240 * Changelog: add #8251 * remove AL card change
Elasticsearch doesn’t guarantee the order of returned Aggregations will
match the input order, which leads to unexpected behavior when
rendering the Aggregations in the Widget.
Adds code to re-order the Aggregation results to match the ordering as
passed to
Jetpack_Search::set_filters().Fixes #8096