From e87501174628302b46f5e1b9dd93b7d6a84a67ba Mon Sep 17 00:00:00 2001 From: Jake Collins Date: Thu, 13 Apr 2023 13:23:10 -0500 Subject: [PATCH 1/7] Use `autocomplete.phrase` when phrase is detected. --- packages/marko-web-search/loaders/search.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/marko-web-search/loaders/search.js b/packages/marko-web-search/loaders/search.js index 293d4537c..972d3c0a7 100644 --- a/packages/marko-web-search/loaders/search.js +++ b/packages/marko-web-search/loaders/search.js @@ -66,12 +66,15 @@ module.exports = async ({ apolloBaseCMS, apolloBaseBrowse } = {}, { opSuffix, } = {}) => { if (!apolloBaseCMS || !apolloBaseBrowse) throw new Error('Both the BaseCMS and Base Browse Apollo clients must be provided.'); + const query = (!searchQuery.match(/^".+"$/) && !searchQuery.match(/^'.+'$/)) ? searchQuery : ''; + const phrase = (searchQuery.match(/^".+"$/) || searchQuery.match(/^'.+'$/)) ? searchQuery.replace(/[",']/g, '') : ''; const input = { omitScheduledAndExpiredContent: true, statuses: ['PUBLISHED'], contentTypes, countryCodes, - ...(searchQuery && { search: { query: searchQuery } }), + ...(query && { search: { query } }), + ...(phrase && { autocomplete: { phrase }}), ...((assignedToWebsiteSiteIds.length || assignedToWebsiteSectionIds.length) && { assignedToWebsites: { ...(assignedToWebsiteSiteIds.length && { siteIds: assignedToWebsiteSiteIds }), From fa96c2edb60df7b25bae04748c11cfdb6af158cf Mon Sep 17 00:00:00 2001 From: Shinsina <46794001+Shinsina@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:07:35 -0500 Subject: [PATCH 2/7] Update search.js --- packages/marko-web-search/loaders/search.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/marko-web-search/loaders/search.js b/packages/marko-web-search/loaders/search.js index 972d3c0a7..9473c995b 100644 --- a/packages/marko-web-search/loaders/search.js +++ b/packages/marko-web-search/loaders/search.js @@ -67,14 +67,14 @@ module.exports = async ({ apolloBaseCMS, apolloBaseBrowse } = {}, { } = {}) => { if (!apolloBaseCMS || !apolloBaseBrowse) throw new Error('Both the BaseCMS and Base Browse Apollo clients must be provided.'); const query = (!searchQuery.match(/^".+"$/) && !searchQuery.match(/^'.+'$/)) ? searchQuery : ''; - const phrase = (searchQuery.match(/^".+"$/) || searchQuery.match(/^'.+'$/)) ? searchQuery.replace(/[",']/g, '') : ''; + const phrase = (searchQuery.match(/^".+"$/) || searchQuery.match(/^'.+'$/)) ? searchQuery : ''; const input = { omitScheduledAndExpiredContent: true, statuses: ['PUBLISHED'], contentTypes, countryCodes, ...(query && { search: { query } }), - ...(phrase && { autocomplete: { phrase }}), + ...(phrase && { autocomplete: { phrase } }), ...((assignedToWebsiteSiteIds.length || assignedToWebsiteSectionIds.length) && { assignedToWebsites: { ...(assignedToWebsiteSiteIds.length && { siteIds: assignedToWebsiteSiteIds }), From 65c05a4aa2426cf183b59edebb60610b0d593b94 Mon Sep 17 00:00:00 2001 From: Jake Collins Date: Mon, 17 Apr 2023 08:57:56 -0500 Subject: [PATCH 3/7] Make behavior configurable --- packages/marko-web-search/components/query.marko | 2 ++ packages/marko-web-search/loaders/search.js | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/marko-web-search/components/query.marko b/packages/marko-web-search/components/query.marko index af12bd109..93bcf7826 100644 --- a/packages/marko-web-search/components/query.marko +++ b/packages/marko-web-search/components/query.marko @@ -4,6 +4,7 @@ $ const { apollo: apolloBaseCMS, $baseBrowse: apolloBaseBrowse, config, + site } = out.global; $ const { assignedToWebsiteSectionIds } = input; @@ -21,6 +22,7 @@ $ const params = { ), queryFragment: input.queryFragment, opSuffix: input.opSuffix, + enableNewSearch: site.get('enableNewSearch', false), }; diff --git a/packages/marko-web-search/loaders/search.js b/packages/marko-web-search/loaders/search.js index 9473c995b..3875a2231 100644 --- a/packages/marko-web-search/loaders/search.js +++ b/packages/marko-web-search/loaders/search.js @@ -64,17 +64,16 @@ module.exports = async ({ apolloBaseCMS, apolloBaseBrowse } = {}, { queryFragment, opSuffix, + enableNewSearch = false, } = {}) => { if (!apolloBaseCMS || !apolloBaseBrowse) throw new Error('Both the BaseCMS and Base Browse Apollo clients must be provided.'); - const query = (!searchQuery.match(/^".+"$/) && !searchQuery.match(/^'.+'$/)) ? searchQuery : ''; - const phrase = (searchQuery.match(/^".+"$/) || searchQuery.match(/^'.+'$/)) ? searchQuery : ''; const input = { omitScheduledAndExpiredContent: true, statuses: ['PUBLISHED'], contentTypes, countryCodes, - ...(query && { search: { query } }), - ...(phrase && { autocomplete: { phrase } }), + ...(!enableNewSearch && searchQuery && { search: { query: searchQuery } }), + ...(enableNewSearch && searchQuery && { autocomplete: { phrase: searchQuery }}), ...((assignedToWebsiteSiteIds.length || assignedToWebsiteSectionIds.length) && { assignedToWebsites: { ...(assignedToWebsiteSiteIds.length && { siteIds: assignedToWebsiteSiteIds }), From 196404ce664c06cca7dad7ad0bd8e5dba8cf6d64 Mon Sep 17 00:00:00 2001 From: Jake Collins Date: Mon, 17 Apr 2023 09:03:36 -0500 Subject: [PATCH 4/7] Fix spacing of }'s --- packages/marko-web-search/loaders/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/marko-web-search/loaders/search.js b/packages/marko-web-search/loaders/search.js index 3875a2231..242f2985b 100644 --- a/packages/marko-web-search/loaders/search.js +++ b/packages/marko-web-search/loaders/search.js @@ -73,7 +73,7 @@ module.exports = async ({ apolloBaseCMS, apolloBaseBrowse } = {}, { contentTypes, countryCodes, ...(!enableNewSearch && searchQuery && { search: { query: searchQuery } }), - ...(enableNewSearch && searchQuery && { autocomplete: { phrase: searchQuery }}), + ...(enableNewSearch && searchQuery && { autocomplete: { phrase: searchQuery } }), ...((assignedToWebsiteSiteIds.length || assignedToWebsiteSectionIds.length) && { assignedToWebsites: { ...(assignedToWebsiteSiteIds.length && { siteIds: assignedToWebsiteSiteIds }), From 5b0aecd4f108b1d85844d73c61c0efc18ec22d88 Mon Sep 17 00:00:00 2001 From: Shinsina <46794001+Shinsina@users.noreply.github.com> Date: Thu, 20 Apr 2023 17:29:55 -0500 Subject: [PATCH 5/7] Update query.marko --- packages/marko-web-search/components/query.marko | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/marko-web-search/components/query.marko b/packages/marko-web-search/components/query.marko index 93bcf7826..59c9ed3c0 100644 --- a/packages/marko-web-search/components/query.marko +++ b/packages/marko-web-search/components/query.marko @@ -22,7 +22,7 @@ $ const params = { ), queryFragment: input.queryFragment, opSuffix: input.opSuffix, - enableNewSearch: site.get('enableNewSearch', false), + useAutocomplete: site.get('useAutocomplete', false), }; From 9c0c3e8cbd078f5fc963fb33dfbd8af2eb27fbd3 Mon Sep 17 00:00:00 2001 From: Shinsina <46794001+Shinsina@users.noreply.github.com> Date: Thu, 20 Apr 2023 17:30:27 -0500 Subject: [PATCH 6/7] Update search.js --- packages/marko-web-search/loaders/search.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/marko-web-search/loaders/search.js b/packages/marko-web-search/loaders/search.js index 242f2985b..3054d6bff 100644 --- a/packages/marko-web-search/loaders/search.js +++ b/packages/marko-web-search/loaders/search.js @@ -64,7 +64,7 @@ module.exports = async ({ apolloBaseCMS, apolloBaseBrowse } = {}, { queryFragment, opSuffix, - enableNewSearch = false, + useAutocomplete = false, } = {}) => { if (!apolloBaseCMS || !apolloBaseBrowse) throw new Error('Both the BaseCMS and Base Browse Apollo clients must be provided.'); const input = { @@ -72,8 +72,8 @@ module.exports = async ({ apolloBaseCMS, apolloBaseBrowse } = {}, { statuses: ['PUBLISHED'], contentTypes, countryCodes, - ...(!enableNewSearch && searchQuery && { search: { query: searchQuery } }), - ...(enableNewSearch && searchQuery && { autocomplete: { phrase: searchQuery } }), + ...(!useAutocomplete && searchQuery && { search: { query: searchQuery } }), + ...(useAutocomplete && searchQuery && { autocomplete: { phrase: searchQuery } }), ...((assignedToWebsiteSiteIds.length || assignedToWebsiteSectionIds.length) && { assignedToWebsites: { ...(assignedToWebsiteSiteIds.length && { siteIds: assignedToWebsiteSiteIds }), From 866f428a1e4387d0c499a0bd032bfe253d3539c1 Mon Sep 17 00:00:00 2001 From: Josh Worden Date: Fri, 21 Apr 2023 08:44:47 -0500 Subject: [PATCH 7/7] read from search config --- packages/marko-web-search/components/query.marko | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/marko-web-search/components/query.marko b/packages/marko-web-search/components/query.marko index 59c9ed3c0..85e2abe93 100644 --- a/packages/marko-web-search/components/query.marko +++ b/packages/marko-web-search/components/query.marko @@ -22,7 +22,7 @@ $ const params = { ), queryFragment: input.queryFragment, opSuffix: input.opSuffix, - useAutocomplete: site.get('useAutocomplete', false), + useAutocomplete: site.get('search.useAutocomplete', false), };