Skip to content

Commit

Permalink
fix error when filter value not found in items set (#130)
Browse files Browse the repository at this point in the history
* fix error when filter value not found in items set

* added conjunction false test

* add test for single non existing value
  • Loading branch information
aurelienroux authored Sep 14, 2023
1 parent faa006e commit d0a63a6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const combination_indexes = function(facets, filters) {
const filter_val = disjunctive_filter[1];

filter_keys.push(filter_key);
facet_union = facet_union.new_union(facets['bits_data'][filter_key][filter_val]);
facet_union = facet_union.new_union(facets['bits_data'][filter_key][filter_val] || new FastBitSet([]));
indexes[filter_key] = facet_union;
});
}
Expand Down Expand Up @@ -311,7 +311,7 @@ const facets_ids = function(facets_data, filters) {
filters.forEach(filter => {

++i;
output = output.new_union(facets_data[field][filter]);
output = output.new_union(facets_data[field][filter] || new FastBitSet([]));
});
});

Expand Down
55 changes: 55 additions & 0 deletions tests/searchSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const assert = require('assert');
const { clone } = require('lodash');
const items = require('./fixtures/items.json');
const movies = require('./fixtures/movies.json');
let itemsjs = require('./../src/index')();
Expand Down Expand Up @@ -195,6 +196,60 @@ describe('search', function() {
done();
});

it('makes search with non existing filter value with conjunction true should return no results', function test(done) {

const itemsjs = require('./../index')(items, configuration);

const result = itemsjs.search({
filters: {
category: ['drama', 'thriller']
}
});

assert.equal(result.data.items.length, 0);
assert.equal(result.data.aggregations.tags.buckets[0].doc_count, 0);

done();
});

it('makes search with non existing filter value with conjunction false should return results', function test(done) {

const localConfiguration = clone(configuration);
localConfiguration.aggregations.category.conjunction = false;

const itemsjs = require('./../index')(items, localConfiguration);

const result = itemsjs.search({
filters: {
category: ['drama', 'thriller']
}
});

assert.equal(result.data.items.length, 2);
assert.equal(result.data.aggregations.tags.buckets[0].doc_count, 2);

done();
});

it('makes search with non existing single filter value with conjunction false should return no results', function test(done) {

const localConfiguration = clone(configuration);
localConfiguration.aggregations.category.conjunction = false;

const itemsjs = require('./../index')(items, configuration);

const result = itemsjs.search({
filters: {
category: ['thriller']
}
});

assert.equal(result.data.items.length, 0);
assert.equal(result.data.aggregations.tags.buckets[0].doc_count, 0);

done();
});

it('throws an error if name does not exist', function test(done) {

const itemsjs = require('./../index')(items, {
Expand Down

0 comments on commit d0a63a6

Please sign in to comment.