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

Improvement request : buckets sort #110

Closed Bartaf83 closed 2 years ago

Bartaf83 commented 2 years ago

It could be interesting to be able to sort buckets (alphabetically at least) or by any other possible criteria.

We wish see such as feature soon in your module.

Best Regards!

Ruitjes commented 2 years ago

Hi @Bartaf83,

I think this is already possible with Itemsjs version 2.1.15. You can check #109 tests/facetSortingSpec.js where the feature is added.

For example alphabetically facet sorting:

describe('facet sorting', function() {

  it('sort by key', function test(done) {

    const result = require('./../index')(items, {
      aggregations: {
        genres: {
          sort: ['key'],
        }
      }
    }).aggregation({
      name: 'genres',
    });

    assert.deepEqual(result.data.buckets.map(v => v.key), ['Comedy', 'Drama', 'Horror', 'Romance', 'Western']);

    done();
  });
cigolpl commented 2 years ago

It will require better documentation / guide so any help is needed here but I am closing now because this feature is available