Skip to content

Commit

Permalink
Merge pull request #37 from social-native/feat/add-terms-filter
Browse files Browse the repository at this point in the history
Feat: add terms filter
  • Loading branch information
erhathaway authored Apr 3, 2020
2 parents 304202f + 085c9a2 commit 546c109
Show file tree
Hide file tree
Showing 7 changed files with 564 additions and 6 deletions.
15 changes: 13 additions & 2 deletions dev/app/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
PrefixSuggestion,
RangeFilter,
History,
localStorageHistoryPersister
localStorageHistoryPersister,
TermsFilter
} from '../../src';
import {IRangeConfig} from '../../src/filters/range_filter';
import {reaction} from 'mobx';
Expand Down Expand Up @@ -67,6 +68,15 @@ const customPrefixSuggestion = new PrefixSuggestion({
fieldNameModifierAggs: (fieldName: string) => `${fieldName}.keyword`
});

const customTermsFilter = new TermsFilter({
defaultFilterKind: 'must',
defaultFilterInclusion: 'include',
getCount: false,
aggsEnabled: false,
fieldNameModifierQuery: (fieldName: string) => `${fieldName}.keyword`,
fieldNameModifierAggs: (fieldName: string) => `${fieldName}.keyword`
});

const defaultRangeFilterConfig: IRangeConfig = {
field: '',
aggsEnabled: false,
Expand Down Expand Up @@ -106,7 +116,8 @@ const creatorCRM = new Manager(client, {
// 'user_profile.children.year_born'
// ],
filters: {
range: customRangeFilter
range: customRangeFilter,
terms: customTermsFilter
},
suggestions: {
prefix: customPrefixSuggestion
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@social-native/snpkg-client-elasticsearch",
"version": "4.0.0",
"version": "4.1.0",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down
1 change: 1 addition & 0 deletions src/filters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {default as ExistsFilter} from './exists_filter';
export {default as MultiSelectFilter} from './multi_select_filter';
export {default as DateRangeFilter} from './date_range_filter';
export {default as GeoFilter} from './geo_filter';
export {default as TermsFilter} from './terms_filter';

export {default as filterUtils} from './utils';

Expand Down
6 changes: 5 additions & 1 deletion src/filters/multi_select_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,12 @@ class MultiSelectFilter<Fields extends string> extends BaseFilter<
return objKeys(filter as MultiSelectFieldFilter).reduce(
(newQuery, selectedValue) => {
const selectedValueFilter = filter[selectedValue];

const inclusion =
selectedValueFilter.inclusion || config.defaultFilterInclusion;

const newFilter =
selectedValueFilter.inclusion === 'include'
inclusion === 'include'
? {match: {[fieldNameModifier(name)]: selectedValue}}
: {
bool: {
Expand Down
Loading

0 comments on commit 546c109

Please sign in to comment.