fix: remove onlyOnTypes from mustMatch

- Execute sort on all types (results include only
types that are possible to sort)

- mustMatch filters types with and AND (e.g. a type
that can be sorted by distance must be building and
room and point of interest)

Closes #83
This commit is contained in:
Jovan Krunić
2021-03-26 16:09:06 +01:00
committed by Rainer Killinger
parent 9488451080
commit 1d5f99b1fa
2 changed files with 1 additions and 39 deletions

View File

@@ -509,7 +509,7 @@ export interface ESGeoDistanceSortArguments {
[field: string]: {
/**
* Latitute
* Latitude
*/
lat: number;

View File

@@ -24,7 +24,6 @@ import {
SCSearchSort,
SCSportCoursePriceGroup,
SCThingsField,
SCThingType,
} from '@openstapps/core';
import {
ElasticsearchConfig,
@@ -317,40 +316,6 @@ export function buildQuery(
elasticsearchConfig: ElasticsearchConfig,
): ESFunctionScoreQuery {
// if a sort is used it, we may have to narrow down the types so the sort is executable
let typeFiltersToAppend: ESTypeFilter[] = [];
if (typeof params.sort !== 'undefined') {
params.sort.forEach((sort) => {
// types that the sort is supported on
const types: SCThingType[] = [];
defaultConfig.backend.sortableFields
.filter((sortableField) => {
return sortableField.fieldName === sort.arguments.field && sortableField.sortTypes.indexOf(sort.type) > -1;
})
.forEach((sortableField) => {
if (typeof sortableField.onlyOnTypes !== 'undefined') {
sortableField.onlyOnTypes.forEach((scType) => {
if (types.indexOf(scType) === -1) {
types.push(scType);
}
});
}
});
if (types.length > 0) {
typeFiltersToAppend = types.map((type) => {
return {
type: {
value: type,
},
};
});
}
});
}
// if config provides an minMatch parameter we use query_string instead of match query
let query;
if (typeof elasticsearchConfig.query === 'undefined') {
@@ -429,9 +394,6 @@ export function buildQuery(
if (typeof params.filter !== 'undefined') {
mustMatch.push(buildFilter(params.filter));
}
// add type filters for sorts
mustMatch.push.apply(mustMatch, typeFiltersToAppend);
}
return functionScoreQuery;