From d010b54bce8d8e5d8c84960e45ee793975ef0cfb Mon Sep 17 00:00:00 2001 From: Ketan <73937490+devketanpro@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:28:07 +0530 Subject: [PATCH] Search in Planning should recognise CVs case insensitive and not only the name field but also the translations [SDBELGA-816]] (#2010) * update event subject schema to use analyzer and translations [SDBELGA-818] * use dynamic property in schema * address comment * add tests * update planning subject schema * Refactored code and minor changes * remove unwanted code --- server/features/search_events.feature | 44 ++++++++++++++++++++++++- server/planning/events/events_schema.py | 2 +- server/planning/planning/planning.py | 23 ++++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/server/features/search_events.feature b/server/features/search_events.feature index 71d98519d..6faf89bcd 100644 --- a/server/features/search_events.feature +++ b/server/features/search_events.feature @@ -51,7 +51,7 @@ Feature: Event Search "start": "2016-01-02T00:00:00+0000", "end": "2016-01-03T00:00:00+0000" }, - "subject": [{"qcode": "test qcode 2", "name": "test name"}], + "subject": [{"qcode": "test qcode 2", "name": "test name", "translations": {"name": {"nl": "NL TEST"}}}], "location": [{"qcode": "test qcode", "name": "test name"}], "calendars": [ {"qcode": "entertainment", "name": "entertainment"} @@ -223,6 +223,48 @@ Feature: Event Search When we get "/events_planning_search?repo=events&only_future=false&priority=1" Then we get list with 0 items + When we get "/events_planning_search?repo=events&only_future=false&full_text=test name" + Then we get list with 3 items + """ + {"_items": [ + {"_id": "event_123"}, + {"_id": "event_456"}, + {"_id": "event_786"} + ]} + """ + When we get "/events_planning_search?repo=events&only_future=false&full_text=TEST NAME" + Then we get list with 3 items + """ + {"_items": [ + {"_id": "event_123"}, + {"_id": "event_456"}, + {"_id": "event_786"} + ]} + """ + When we get "/events_planning_search?repo=events&only_future=false&full_text=Test Name" + Then we get list with 3 items + """ + {"_items": [ + {"_id": "event_123"}, + {"_id": "event_456"}, + {"_id": "event_786"} + ]} + """ + When we get "/events_planning_search?repo=events&only_future=false&full_text=NL TEST" + Then we get list with 1 items + """ + {"_items": [ + {"_id": "event_456"} + ]} + """ + When we get "/events_planning_search?repo=events&only_future=false&full_text=nl test" + Then we get list with 1 items + """ + {"_items": [ + {"_id": "event_456"} + ]} + """ + @auth Scenario: Search by event specific parameters When we get "/events_planning_search?repo=events&only_future=false&slugline=test1%20OR%20test2" diff --git a/server/planning/events/events_schema.py b/server/planning/events/events_schema.py index 9b13c612a..d0c7034d9 100644 --- a/server/planning/events/events_schema.py +++ b/server/planning/events/events_schema.py @@ -195,7 +195,7 @@ "mapping": {"properties": {"qcode": not_analyzed, "name": not_analyzed}}, }, # Content metadata - "subject": metadata_schema["subject"], + "subject": planning_schema["subject"], "slugline": metadata_schema["slugline"], # Item metadata "location": { diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 40f0f7d20..8712345f6 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -1831,7 +1831,28 @@ def _iter_recurring_plannings_to_update(self, updates, original, update_method): "description_text": metadata_schema["description_text"], "internal_note": {"type": "string", "nullable": True}, "anpa_category": metadata_schema["anpa_category"], - "subject": metadata_schema["subject"], + "subject": { + "type": "list", + "mapping": { + "type": "object", + "dynamic": False, + "properties": { + "qcode": not_analyzed, + "name": { + "type": "keyword", + "fields": { + "analyzed": string_with_analyzer, + }, + }, + "scheme": not_analyzed, + "translations": { + "type": "object", + "dynamic": False, + "properties": {"name": {"type": "object", "dynamic": True}}, + }, + }, + }, + }, "genre": metadata_schema["genre"], "company_codes": metadata_schema["company_codes"], # Content Metadata - See IPTC-G2-Implementation_Guide 16.2