diff --git a/packages/marko-web-search/components/sort-by/index.marko b/packages/marko-web-search/components/sort-by/index.marko index 46ff15860..75405badd 100644 --- a/packages/marko-web-search/components/sort-by/index.marko +++ b/packages/marko-web-search/components/sort-by/index.marko @@ -1,6 +1,5 @@ import { get, getAsArray, getAsObject } from "@parameter1/base-cms-object-path"; import { dasherize } from "@parameter1/base-cms-inflector"; -import defaultValue from "@parameter1/base-cms-marko-core/utils/default-value"; import { isFunction } from '@parameter1/base-cms-utils'; $ const { $markoWebSearch: search, i18n } = out.global; @@ -16,7 +15,7 @@ $ const options = isFunction(i18n) ? [ $ const { searchQuery, sortField } = search.input; - $ const selectedId = input.sortField || sortField; + $ const selectedId = sortField; (type.label ? ({ @@ -68,6 +71,7 @@ class MarkoWebSearchConfig { this.queryParams = new MarkoWebSearchQueryParamConfig({ resultsPerPage, contentTypeIds: this.contentTypeObjects.map(({ id }) => id), + defaultSortField, }); } } diff --git a/packages/marko-web-search/config/query-params.js b/packages/marko-web-search/config/query-params.js index 4f7687a65..ffa0a7abb 100644 --- a/packages/marko-web-search/config/query-params.js +++ b/packages/marko-web-search/config/query-params.js @@ -26,6 +26,7 @@ class MarkoWebSearchQueryParamConfig { constructor({ resultsPerPage = {}, contentTypeIds = [], + defaultSortField = 'PUBLISHED', } = {}) { this.params = new Map(); @@ -71,7 +72,7 @@ class MarkoWebSearchQueryParamConfig { }) .add('sortField', { type: String, - defaultValue: 'PUBLISHED', + defaultValue: defaultSortField, validator: (v) => sortFieldSet.has(v), }) .add('sortOrder', { diff --git a/packages/marko-web-theme-monorail/routes/search.js b/packages/marko-web-theme-monorail/routes/search.js index 617a63d9d..7e49565e9 100644 --- a/packages/marko-web-theme-monorail/routes/search.js +++ b/packages/marko-web-theme-monorail/routes/search.js @@ -7,11 +7,13 @@ module.exports = (app, siteConfig) => { const { contentTypes = ['Article', 'Blog', 'Company', 'Podcast', 'Product', 'Video', 'Whitepaper'], assignedToWebsiteSectionIds, + defaultSortField, } = getAsObject(siteConfig, 'search'); const config = new MarkoWebSearchConfig({ resultsPerPage: { default: 18 }, contentTypes, assignedToWebsiteSectionIds, + defaultSortField, }); app.get('/search', (req, res, next) => { if (!get(req, 'query.searchQuery') && get(req, 'query.sortField')) { diff --git a/packages/marko-web-theme-monorail/templates/search.marko b/packages/marko-web-theme-monorail/templates/search.marko index 44a191605..208c8fb06 100644 --- a/packages/marko-web-theme-monorail/templates/search.marko +++ b/packages/marko-web-theme-monorail/templates/search.marko @@ -17,10 +17,6 @@ $ const description = i18nIsFunction ? `${i18n("Search")} ${config.siteName()}` $ const currentPage = search.getCurrentPage(); -$ const overrideSortField = get(site, 'config.setSearchSortFieldToScore'); -$ const searchQueryPresent = (search.query.searchQuery && search.query.searchQuery !== ''); -$ const setDefaultSortField = (searchQueryPresent && !search.query.sortField && overrideSortField); -$ const sortField = setDefaultSortField ? 'SCORE' : search.input.sortField; $ const sponsorLogo = site.get('search.sponsorLogos.page'); @@ -73,7 +69,7 @@ $ const sponsorLogo = site.get('search.sponsorLogos.page');
- +
Sponsored by @@ -91,7 +87,7 @@ $ const sponsorLogo = site.get('search.sponsorLogos.page');