-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update aggregations sort this update add the ability to sort aggregations using custom array, it remove the sorting limitiation by the predefined 'selected', 'key', 'doc_count' ... no you can Use something like ''sort['key', 'doc_count']" in aggresgations. * added tests and info in readme Co-authored-by: Houcine Cherif <[email protected]>
- Loading branch information
1 parent
ad5ada6
commit 61efad8
Showing
6 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const items = [{ | ||
genres: 'Western' | ||
}, { | ||
genres: 'Western' | ||
}, { | ||
genres: 'Comedy' | ||
}, { | ||
genres: 'Drama' | ||
}, { | ||
genres: 'Horror' | ||
}, { | ||
genres: 'Romance' | ||
}, { | ||
genres: 'Western' | ||
}]; | ||
|
||
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('sort by key descending', function test(done) { | ||
|
||
const result = require('./../index')(items, { | ||
aggregations: { | ||
genres: { | ||
sort: ['key'], | ||
order: ['desc'] | ||
} | ||
} | ||
}).aggregation({ | ||
name: 'genres', | ||
}); | ||
|
||
assert.deepEqual(result.data.buckets.map(v => v.key), ['Western', 'Romance', 'Horror', 'Drama', 'Comedy']); | ||
|
||
done(); | ||
}); | ||
|
||
it('sort by doc_count', function test(done) { | ||
|
||
const result = require('./../index')(items, { | ||
aggregations: { | ||
genres: { | ||
sort: ['doc_count'], | ||
order: ['desc'], | ||
} | ||
} | ||
}).aggregation({ | ||
name: 'genres', | ||
}); | ||
|
||
assert.deepEqual(result.data.buckets.map(v => v.key), ['Western', 'Comedy', 'Drama', 'Horror', 'Romance']); | ||
|
||
done(); | ||
}); | ||
|
||
it('sort by doc_count and key and order key desc', function test(done) { | ||
|
||
const result = require('./../index')(items, { | ||
aggregations: { | ||
genres: { | ||
sort: ['doc_count', 'key'], | ||
order: ['desc', 'desc'], | ||
} | ||
} | ||
}).aggregation({ | ||
name: 'genres', | ||
}); | ||
|
||
assert.deepEqual(result.data.buckets.map(v => v.key), ['Western', 'Romance', 'Horror', 'Drama', 'Comedy']); | ||
|
||
done(); | ||
}); | ||
|
||
}); | ||
|