Skip to content

Commit

Permalink
Fix creating filters for non-distinct values in the embedded search (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic committed May 12, 2021
1 parent a76677e commit 86ab342
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,22 @@ describe('Generate filters', () => {
[FIELD.name]: ANOTHER_PHRASE,
});
});

it('should use only distinct values', () => {
const ANOTHER_PHRASE = 'another-value';
const filters = generateFilters(
mockFilterManager,
FIELD,
[PHRASE_VALUE, ANOTHER_PHRASE, PHRASE_VALUE, ANOTHER_PHRASE],
'',
INDEX_NAME
);
expect(filters).toHaveLength(2);
expect((filters[0] as PhraseFilter).query.match_phrase).toEqual({
[FIELD.name]: PHRASE_VALUE,
});
expect((filters[1] as PhraseFilter).query.match_phrase).toEqual({
[FIELD.name]: ANOTHER_PHRASE,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function generateFilters(
operation: string,
index: string
): Filter[] {
values = Array.isArray(values) ? values : [values];
values = Array.isArray(values) ? _.uniq(values) : [values];
const fieldObj = (_.isObject(field)
? field
: {
Expand Down

0 comments on commit 86ab342

Please sign in to comment.