itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use
Apache License 2.0
350 stars 41 forks source link

Aggregations are always ordered by selected item first #94

Closed lhoucinecherif closed 2 years ago

lhoucinecherif commented 3 years ago

Hi, Can we make aggregations sorting more flexible, to prevent the selected items from going to the top of the list

here an example :

image

when I select 2022, it go to the top of the list, in my case it should stay at it initial position (ordered by terms) image

It make some confusion for users when selecting many items : the affected code is in the helper.js file :

if (sort === 'term') { buckets = .orderBy(buckets, ['selected', 'key'], ['desc', order || 'asc']); } else { buckets = .orderBy(buckets, ['selected', 'doc_count', 'key'], ['desc', order || 'desc', 'asc']); }

the 'selected' key is hard coded in this file, it should be more flexible so we can order with custom criteria , or simply remove the 'selected' param if not needed.

Thanks

cigolpl commented 3 years ago

Hey,

This issue is related: https://github.com/itemsapi/itemsjs/issues/39

You can make a PR which makes this behavior (selected filters on top) configurable then I'll review and merge it