mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 01:22:54 +00:00
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:
committed by
Rainer Killinger
parent
9488451080
commit
1d5f99b1fa
@@ -509,7 +509,7 @@ export interface ESGeoDistanceSortArguments {
|
|||||||
|
|
||||||
[field: string]: {
|
[field: string]: {
|
||||||
/**
|
/**
|
||||||
* Latitute
|
* Latitude
|
||||||
*/
|
*/
|
||||||
lat: number;
|
lat: number;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
SCSearchSort,
|
SCSearchSort,
|
||||||
SCSportCoursePriceGroup,
|
SCSportCoursePriceGroup,
|
||||||
SCThingsField,
|
SCThingsField,
|
||||||
SCThingType,
|
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
import {
|
import {
|
||||||
ElasticsearchConfig,
|
ElasticsearchConfig,
|
||||||
@@ -317,40 +316,6 @@ export function buildQuery(
|
|||||||
elasticsearchConfig: ElasticsearchConfig,
|
elasticsearchConfig: ElasticsearchConfig,
|
||||||
): ESFunctionScoreQuery {
|
): 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
|
// if config provides an minMatch parameter we use query_string instead of match query
|
||||||
let query;
|
let query;
|
||||||
if (typeof elasticsearchConfig.query === 'undefined') {
|
if (typeof elasticsearchConfig.query === 'undefined') {
|
||||||
@@ -429,9 +394,6 @@ export function buildQuery(
|
|||||||
if (typeof params.filter !== 'undefined') {
|
if (typeof params.filter !== 'undefined') {
|
||||||
mustMatch.push(buildFilter(params.filter));
|
mustMatch.push(buildFilter(params.filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add type filters for sorts
|
|
||||||
mustMatch.push.apply(mustMatch, typeFiltersToAppend);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionScoreQuery;
|
return functionScoreQuery;
|
||||||
|
|||||||
Reference in New Issue
Block a user