feat: add support for multiple values in value filter

This commit is contained in:
Wieland Schöbl
2021-04-07 11:40:28 +02:00
committed by Rainer Killinger
parent 15ac0e2f59
commit de60311bd0
4 changed files with 200 additions and 82 deletions

View File

@@ -274,14 +274,21 @@ export interface ElasticsearchConfig {
/**
* An elasticsearch term filter
*/
export interface ESTermFilter {
export type ESTermFilter = {
/**
* Definition of a term to match
*/
term: {
[fieldName: string]: string;
};
}
} | {
/**
* Definition of terms to match (or)
*/
terms: {
[fieldName: string]: string[];
};
};
export interface ESGenericRange<T> {
/**
@@ -381,7 +388,7 @@ export interface ESGeoDistanceFilterArguments {
[fieldName: string]: {
/**
* Latitute
* Latitude
*/
lat: number;

View File

@@ -99,11 +99,14 @@ export function buildFilter(filter: SCSearchFilter):
switch (filter.type) {
case 'value':
const filterObj: { [field: string]: string; } = {};
filterObj[`${filter.arguments.field}.raw`] = filter.arguments.value;
return {
term: filterObj,
return Array.isArray(filter.arguments.value) ? {
terms: {
[`${filter.arguments.field}.raw`]: filter.arguments.value,
},
} : {
term: {
[`${filter.arguments.field}.raw`]: filter.arguments.value,
},
};
case 'availability':
const startRangeFilter: {
@@ -220,7 +223,7 @@ export function buildFilter(filter: SCSearchFilter):
}
/**
* Builds scorings functions from boosting config
* Builds scoring functions from boosting config
* @param boostings Backend boosting configuration for contexts and types
* @param context The context of the app from where the search was initiated
*/