From 296c683e2c7e7e37326271457fceb0a777de22a6 Mon Sep 17 00:00:00 2001 From: eyal rozen Date: Wed, 8 Jul 2026 19:29:49 +0300 Subject: [PATCH 1/4] feat: search for placetyped and non placetyped --- src/location/DAL/queries.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/location/DAL/queries.ts b/src/location/DAL/queries.ts index a3ae876..42a680a 100644 --- a/src/location/DAL/queries.ts +++ b/src/location/DAL/queries.ts @@ -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: { From 27a1920086dcd2ce26aa62652417ae7c2c85e2bc Mon Sep 17 00:00:00 2001 From: eyal rozen Date: Wed, 8 Jul 2026 20:01:41 +0300 Subject: [PATCH 2/4] test: update test to new logic --- tests/integration/location/location.spec.ts | 18 +++++++++--------- tests/integration/location/utils.ts | 13 +++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/integration/location/location.spec.ts b/tests/integration/location/location.spec.ts index bde71c0..57d5c57 100644 --- a/tests/integration/location/location.spec.ts +++ b/tests/integration/location/location.spec.ts @@ -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; @@ -75,7 +75,7 @@ describe('/search/location', function () { // expect(response).toSatisfyApiSpec(); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( { ...requestParams, }, @@ -127,7 +127,7 @@ describe('/search/location', function () { // expect(response).toSatisfyApiSpec(); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( requestParams, { place_types: ['transportation'], @@ -176,7 +176,7 @@ describe('/search/location', function () { // expect(response).toSatisfyApiSpec(); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( { ...requestParams, }, @@ -265,7 +265,7 @@ describe('/search/location', function () { // expect(response).toSatisfyApiSpec(); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( { ...requestParams, }, @@ -319,7 +319,7 @@ describe('/search/location', function () { // expect(response).toSatisfyApiSpec(); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( requestParams, { name: query, @@ -402,7 +402,7 @@ describe('/search/location', function () { // expect(response).toSatisfyApiSpec(); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( requestParams, { place_types: ['transportation'], @@ -433,7 +433,7 @@ describe('/search/location', function () { // expect(response).toSatisfyApiSpec(); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( requestParams, { place_types: ['education'], @@ -512,7 +512,7 @@ describe('/search/location', function () { expect(response.status).toBe(httpStatusCodes.OK); expect(response.body).toEqual>( - expectedResponse( + expectedResponseUnordered( requestParams, { name: 'los angeles', diff --git a/tests/integration/location/utils.ts b/tests/integration/location/utils.ts index 6f7068b..b82edbb 100644 --- a/tests/integration/location/utils.ts +++ b/tests/integration/location/utils.ts @@ -44,6 +44,19 @@ export const expectedResponse = ( bbox: expect.any(Array) as BBox, }); +export const expectedResponseUnordered = ( + requestParams: GetGeotextSearchParams, + responseParams: Partial['geocoding']['response']>, + arr: MockLocationQueryFeature[], + expect: jest.Expect +): GenericGeocodingResponse => { + const response = expectedResponse(requestParams, responseParams, arr, expect); + return { + ...response, + features: expect.arrayContaining(response.features) as GenericGeocodingResponse['features'], + }; +}; + export const hierarchiesWithAnyWieght = ( hierarchies: GenericGeocodingResponse['geocoding']['response']['hierarchies'], expect: jest.Expect From ec40a28d32281bfc17016976412edb3114659a04 Mon Sep 17 00:00:00 2001 From: eyal rozen Date: Wed, 8 Jul 2026 20:14:51 +0300 Subject: [PATCH 3/4] test: change tests to match the new behavior --- tests/integration/location/location.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration/location/location.spec.ts b/tests/integration/location/location.spec.ts index 57d5c57..7ef69b3 100644 --- a/tests/integration/location/location.spec.ts +++ b/tests/integration/location/location.spec.ts @@ -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], }, }, }, @@ -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], }, }, }, @@ -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], }, }, }, @@ -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], }, }, }, @@ -240,7 +240,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], }, }, }, From 04db9d145e9ede3f40ec25097b4df31077e84751 Mon Sep 17 00:00:00 2001 From: eyal rozen Date: Wed, 8 Jul 2026 20:29:52 +0300 Subject: [PATCH 4/4] test: fix index error --- tests/integration/location/location.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/location/location.spec.ts b/tests/integration/location/location.spec.ts index 7ef69b3..9fe8856 100644 --- a/tests/integration/location/location.spec.ts +++ b/tests/integration/location/location.spec.ts @@ -245,6 +245,8 @@ describe('/search/location', function () { }, }, NY_POLICE_AIRPORT, + OSM_LA_PORT, + GOOGLE_LA_PORT, ], }, ])('it should test airports response with hierrarchy in %s', async ({ query, hierarchies, returnedFeatures }) => {