From 4f5385dc13ac59670668fb4517cac36b90646fc5 Mon Sep 17 00:00:00 2001 From: Leonie Peters Date: Thu, 30 Jan 2025 17:45:02 +0100 Subject: [PATCH 1/5] refactor: do not override query when fulltext search is applied --- packages/portal/src/pages/collections/_type/_.vue | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/portal/src/pages/collections/_type/_.vue b/packages/portal/src/pages/collections/_type/_.vue index ff50642d5d..5e48f273fe 100644 --- a/packages/portal/src/pages/collections/_type/_.vue +++ b/packages/portal/src/pages/collections/_type/_.vue @@ -177,13 +177,19 @@ if (this.entity) { const entityQuery = getEntityQuery([this.entity.id].concat(this.entity.sameAs || [])); overrideParams.qf = [entityQuery]; - if (!this.$route.query.query) { + + if (!this.$route.query.query && !this.fulltextQas?.length) { overrideParams.query = entityQuery; // Triggering best bets. } } return overrideParams; }, + fulltextQas() { + const qaAsArray = this.$route.query.qa ? [].concat(this.$route.query.qa) : null; + + return qaAsArray?.filter?.((rule) => rule.startsWith('fulltext:') || rule.startsWith('NOT fulltext:')); + }, entityId() { return normalizeEntityId(this.$route.params.pathMatch); }, @@ -303,6 +309,11 @@ return labelledMoreInfo; } }, + + mounted() { + console.log(this.$route); + console.log(this.fulltextQas); + }, methods: { handleEntityRelatedCollectionsFetched(relatedCollections) { this.relatedCollections = relatedCollections; From 77d91a42509d4fef248ff292d4d97fe3724caf0d Mon Sep 17 00:00:00 2001 From: Leonie Peters Date: Fri, 31 Jan 2025 10:09:41 +0100 Subject: [PATCH 2/5] refactor: handle collection query override when overriding query by full text --- .../portal/src/components/search/SearchInterface.vue | 6 ++++++ packages/portal/src/pages/collections/_type/_.vue | 11 +---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/portal/src/components/search/SearchInterface.vue b/packages/portal/src/components/search/SearchInterface.vue index 49ec5c2ac5..0ac5a7cfb4 100644 --- a/packages/portal/src/components/search/SearchInterface.vue +++ b/packages/portal/src/components/search/SearchInterface.vue @@ -412,6 +412,12 @@ if (this.advancedSearchQueryCount > 0) { if (this.hasFulltextQa) { + // override query overrides already here to prevent full-text search breaking + if (this.overrideParams.query) { + params.query = this.overrideParams.query; + delete this.overrideParams.query; + } + // If there are any advanced search full-text rules, then // these are promoted to the primary query, and any other query // (from the simple search bar) is demoted to a qf, fielded to diff --git a/packages/portal/src/pages/collections/_type/_.vue b/packages/portal/src/pages/collections/_type/_.vue index 5e48f273fe..be75348659 100644 --- a/packages/portal/src/pages/collections/_type/_.vue +++ b/packages/portal/src/pages/collections/_type/_.vue @@ -178,18 +178,13 @@ const entityQuery = getEntityQuery([this.entity.id].concat(this.entity.sameAs || [])); overrideParams.qf = [entityQuery]; - if (!this.$route.query.query && !this.fulltextQas?.length) { + if (!this.$route.query.query) { overrideParams.query = entityQuery; // Triggering best bets. } } return overrideParams; }, - fulltextQas() { - const qaAsArray = this.$route.query.qa ? [].concat(this.$route.query.qa) : null; - - return qaAsArray?.filter?.((rule) => rule.startsWith('fulltext:') || rule.startsWith('NOT fulltext:')); - }, entityId() { return normalizeEntityId(this.$route.params.pathMatch); }, @@ -310,10 +305,6 @@ } }, - mounted() { - console.log(this.$route); - console.log(this.fulltextQas); - }, methods: { handleEntityRelatedCollectionsFetched(relatedCollections) { this.relatedCollections = relatedCollections; From a7ae132a5fbe70a03b3f02459aa7a8f774ece8b9 Mon Sep 17 00:00:00 2001 From: Leonie Peters Date: Fri, 31 Jan 2025 10:32:35 +0100 Subject: [PATCH 3/5] test: add unit test --- .../components/search/SearchInterface.spec.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/portal/tests/unit/components/search/SearchInterface.spec.js b/packages/portal/tests/unit/components/search/SearchInterface.spec.js index d7cc7d2c0b..889a0eed69 100644 --- a/packages/portal/tests/unit/components/search/SearchInterface.spec.js +++ b/packages/portal/tests/unit/components/search/SearchInterface.spec.js @@ -549,6 +549,41 @@ describe('components/search/SearchInterface', () => { expect(wrapper.vm.apiParams).toEqual(expected); }); + + describe('and a query override', () => { + it('is promoted into query, moving the query override to qf', () => { + const queryOverride = 'skos_concept:"http://data.europeana.eu/concept/001"'; + const $route = { + query: { + qa: [ + 'fulltext:europe', + 'NOT fulltext:united' + ] + } + }; + const expected = { + page: 1, + profile: 'minimal,hits', + query: 'fulltext:europe AND NOT fulltext:united', + qf: [queryOverride, 'contentTier:(1 OR 2 OR 3 OR 4)'], + rows: 24 + }; + + const wrapper = factory({ + propsData: { + overrideParams: { + query: queryOverride + } + }, + mocks: { + $route + } + }); + wrapper.vm.deriveApiParams(); + + expect(wrapper.vm.apiParams).toEqual(expected); + }); + }); }); }); From 93eda9dabbc009f3553a731c53321a7350fb9533 Mon Sep 17 00:00:00 2001 From: Leonie Peters Date: Fri, 31 Jan 2025 10:33:03 +0100 Subject: [PATCH 4/5] test: add e2e test for full text search on entity --- tests/e2e/features/search/advanced.feature | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/e2e/features/search/advanced.feature b/tests/e2e/features/search/advanced.feature index b8af3eba1b..06189447fd 100644 --- a/tests/e2e/features/search/advanced.feature +++ b/tests/e2e/features/search/advanced.feature @@ -12,3 +12,16 @@ Feature: Advanced search And I wait for an `item preview` Then I see a `highlighted search term` with the text "First World War" And I am on an accessible page + + Scenario: Full-text search on a collection page shows hit highlights + When I open an `entity page` + And I click the `search list view toggle icon` + When I click the `toggle advanced search button` + And I enter "paris" in the `advanced search query builder: term control` + And I click the `advanced search query builder: field control` + And I click the `advanced search query builder: fulltext field option` + And I click the `advanced search query builder: modifier control` + And I click the `advanced search query builder: exact modifier option` + And I wait for an `item preview` + Then I see a `highlighted search term` with the text "paris" + And I am on an accessible page From 215a6bc10aa9f0bafa8d5ea91870142a15022695 Mon Sep 17 00:00:00 2001 From: Leonie Peters Date: Fri, 31 Jan 2025 11:39:51 +0100 Subject: [PATCH 5/5] test: rewrite e2e test --- tests/e2e/docker/nightwatch/support/pages.js | 1 + tests/e2e/features/search/advanced.feature | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e2e/docker/nightwatch/support/pages.js b/tests/e2e/docker/nightwatch/support/pages.js index 4c4be2d009..7814428049 100644 --- a/tests/e2e/docker/nightwatch/support/pages.js +++ b/tests/e2e/docker/nightwatch/support/pages.js @@ -21,6 +21,7 @@ const pages = { 'gallery foyer page': `${url}/en/galleries`, 'home page': `${url}/en`, 'Newspapers theme search page': `${url}/en/search?qf=collection%3Anewspaper`, + 'newspaper entity page': `${url}/en/collections/topic/18-newspaper`, 'immersive story page': `${url}/en/stories/melitta-bentz-the-woman-who-invented-the-coffee-filter`, 'item page with a IIIF Image': `${url}/en/item/9200357/BibliographicResource_3000095247457`, 'item page with a IIIF Presentation': `${url}/en/item/9200301/BibliographicResource_3000126341277`, diff --git a/tests/e2e/features/search/advanced.feature b/tests/e2e/features/search/advanced.feature index 06189447fd..c38e85d0ac 100644 --- a/tests/e2e/features/search/advanced.feature +++ b/tests/e2e/features/search/advanced.feature @@ -14,14 +14,14 @@ Feature: Advanced search And I am on an accessible page Scenario: Full-text search on a collection page shows hit highlights - When I open an `entity page` + When I open the `newspaper entity page` And I click the `search list view toggle icon` When I click the `toggle advanced search button` - And I enter "paris" in the `advanced search query builder: term control` + And I enter "berlin" in the `advanced search query builder: term control` And I click the `advanced search query builder: field control` And I click the `advanced search query builder: fulltext field option` And I click the `advanced search query builder: modifier control` And I click the `advanced search query builder: exact modifier option` And I wait for an `item preview` - Then I see a `highlighted search term` with the text "paris" + Then I see a `highlighted search term` with the text "Berlin" And I am on an accessible page