itemsapi / itemsjs

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

Custom Aggregations sorting #101

Closed lhoucinecherif closed 2 years ago

lhoucinecherif commented 2 years ago

Hi, This mini update make aggregations configurable using a custom sorting array (related issue : https://github.com/itemsapi/itemsjs/issues/94) : we can now sort aggregations like this :

const configuration = {
// ...
aggregations: {
 actors: {
      title: 'Actors',
      size: 10,
      // we can use a custom array instead of  the only available 'term'     
      sort: ['key']  // we can play with keys like : 'key', 'doc_count', 'selected' even add multiples keys like ['key', 'doc_count']
    },
}
//...
};

So we can play with all available sorting keys , and override the hardcoded 'selected' key if we want The old behavior is still kept (backwards compatibility )

cigolpl commented 2 years ago

This looks good! Could you also add a test ? This test might be helpful to reproduce your use case https://github.com/itemsapi/itemsjs/blob/master/tests/searchSpec.js#L88

ritz0106 commented 2 years ago

It would be nice to have this feature, do we know when can we have it merged ?

cigolpl commented 2 years ago

This PR is merged with tests. Please look into #109