Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,17 @@ export const getBuckets = function(data, input, aggregations) {
}

const doc_count = v2[1].array().length;
const isSelected = filters.some((f) => String(f) === String(v2[0]));

//hide zero_doc_count facet only if it is not selected
if (
hide_zero_doc_count &&
doc_count === 0 &&
filters.indexOf(v2[0]) === -1
) {
if (hide_zero_doc_count && doc_count === 0 && !isSelected) {
return;
}

return {
key: v2[0],
doc_count: doc_count,
selected: filters.indexOf(v2[0]) !== -1,
selected: isSelected,
};
})
.filter(Boolean);
Expand Down
30 changes: 30 additions & 0 deletions tests/searchSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,36 @@ describe('search', function () {
done();
});

it('marks boolean facets as selected', function test(done) {
const dataset = [
{ boolean: true, string: 'true' },
{ boolean: false, string: 'false' },
];

const itemsjs = itemsJS(dataset, {
aggregations: {
boolean: {},
string: {},
},
});

const result = itemsjs.search({
filters: {
boolean: [true],
string: ['true'],
},
});

const booleanBuckets = result.data.aggregations.boolean.buckets;
const stringBuckets = result.data.aggregations.string.buckets;

assert.equal(booleanBuckets[0].key, 'true');
assert.equal(booleanBuckets[0].selected, true);
assert.equal(stringBuckets[0].selected, true);

done();
});

it('makes search with non existing filter value with conjunction true should return no results', function test(done) {
const itemsjs = itemsJS(items, configuration);

Expand Down