Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/location/DAL/queries.ts
Comment thread
eyalr1100 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,32 @@ export const geotextQuery = (
}
}

if (!name && subPlaceTypes?.length) {
(esQuery.query?.function_score?.query?.bool?.must as QueryDslQueryContainer[]).push(
...[
{
terms: {
[SUB_PLACETYPE_FIELD]: subPlaceTypes,
},
},
{
term: {
text_language: textLanguage,
},
},
]
);
} else {
(esQuery.query?.function_score?.query?.bool?.must as QueryDslQueryContainer[]).push({
const interpretations: QueryDslQueryContainer[] = [
{
match: {
[TEXT_FIELD]: {
query,
fuzziness: disableFuzziness ? undefined : 'AUTO:3,4',
},
},
},
];

if (subPlaceTypes?.length) {
interpretations.push({
bool: {
must: [{ terms: { [SUB_PLACETYPE_FIELD]: subPlaceTypes } }, { term: { text_language: textLanguage } }],
},
});
}

(esQuery.query?.function_score?.query?.bool?.must as QueryDslQueryContainer[]).push({
bool: {
should: interpretations,
minimum_should_match: 1,
},
});

source?.length &&
(esQuery.query?.function_score?.query?.bool?.filter as QueryDslQueryContainer[]).push({
terms: {
Expand Down
30 changes: 16 additions & 14 deletions tests/integration/location/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
LA_ROAD,
} from '../../mockObjects/locations';
import { LocationRequestSender } from './helpers/requestSender';
import { expectedResponse, hierarchiesWithAnyWieght } from './utils';
import { expectedResponse, expectedResponseUnordered, hierarchiesWithAnyWieght } from './utils';
import { getBaseRegisterOptions } from './helpers';

let config: ConfigType;
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('/search/location', function () {
// expect(response).toSatisfyApiSpec();

expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
{
...requestParams,
},
Expand All @@ -90,7 +90,7 @@ describe('/search/location', function () {
...NY_JFK_AIRPORT.properties,
names: {
...NY_JFK_AIRPORT.properties.names,
display: NY_JFK_AIRPORT_DISPLAY_NAMES[0],
display: NY_JFK_AIRPORT_DISPLAY_NAMES[1],
},
},
},
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('/search/location', function () {
// expect(response).toSatisfyApiSpec();

expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
requestParams,
{
place_types: ['transportation'],
Expand All @@ -140,7 +140,7 @@ describe('/search/location', function () {
...NY_JFK_AIRPORT.properties,
names: {
...NY_JFK_AIRPORT.properties.names,
display: NY_JFK_AIRPORT_DISPLAY_NAMES[0],
display: NY_JFK_AIRPORT_DISPLAY_NAMES[1],
},
},
},
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('/search/location', function () {
// expect(response).toSatisfyApiSpec();

expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
{
...requestParams,
},
Expand All @@ -191,7 +191,7 @@ describe('/search/location', function () {
...NY_JFK_AIRPORT.properties,
names: {
...NY_JFK_AIRPORT.properties.names,
display: NY_JFK_AIRPORT_DISPLAY_NAMES[0],
display: NY_JFK_AIRPORT_DISPLAY_NAMES[1],
},
},
},
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('/search/location', function () {
...NY_JFK_AIRPORT.properties,
names: {
...NY_JFK_AIRPORT.properties.names,
display: NY_JFK_AIRPORT_DISPLAY_NAMES[0],
display: NY_JFK_AIRPORT_DISPLAY_NAMES[1],
},
},
},
Expand All @@ -240,11 +240,13 @@ describe('/search/location', function () {
...NY_JFK_AIRPORT.properties,
names: {
...NY_JFK_AIRPORT.properties.names,
display: NY_JFK_AIRPORT_DISPLAY_NAMES[0],
display: NY_JFK_AIRPORT_DISPLAY_NAMES[1],
},
},
},
NY_POLICE_AIRPORT,
OSM_LA_PORT,
GOOGLE_LA_PORT,
],
},
])('it should test airports response with hierrarchy in %s', async ({ query, hierarchies, returnedFeatures }) => {
Expand All @@ -265,7 +267,7 @@ describe('/search/location', function () {
// expect(response).toSatisfyApiSpec();

expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
{
...requestParams,
},
Expand Down Expand Up @@ -319,7 +321,7 @@ describe('/search/location', function () {
// expect(response).toSatisfyApiSpec();

expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
requestParams,
{
name: query,
Expand Down Expand Up @@ -402,7 +404,7 @@ describe('/search/location', function () {
// expect(response).toSatisfyApiSpec();

expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
requestParams,
{
place_types: ['transportation'],
Expand Down Expand Up @@ -433,7 +435,7 @@ describe('/search/location', function () {
// expect(response).toSatisfyApiSpec();

expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
requestParams,
{
place_types: ['education'],
Expand Down Expand Up @@ -512,7 +514,7 @@ describe('/search/location', function () {

expect(response.status).toBe(httpStatusCodes.OK);
expect(response.body).toEqual<GenericGeocodingResponse<Feature>>(
expectedResponse(
expectedResponseUnordered(
requestParams,
{
name: 'los angeles',
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/location/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ export const expectedResponse = (
bbox: expect.any(Array) as BBox,
});

export const expectedResponseUnordered = (
requestParams: GetGeotextSearchParams,
responseParams: Partial<GenericGeocodingResponse<Feature>['geocoding']['response']>,
arr: MockLocationQueryFeature[],
expect: jest.Expect
): GenericGeocodingResponse<Feature> => {
const response = expectedResponse(requestParams, responseParams, arr, expect);
return {
...response,
features: expect.arrayContaining(response.features) as GenericGeocodingResponse<Feature>['features'],
};
};

export const hierarchiesWithAnyWieght = (
hierarchies: GenericGeocodingResponse<Feature>['geocoding']['response']['hierarchies'],
expect: jest.Expect
Expand Down
Loading