itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improvement request : buckets sort

Bartaf83 opened this issue · comments

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!

commented

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();
  });

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