diff --git a/app/assets/javascripts/admin/addon/services/admin-search-data-source.js b/app/assets/javascripts/admin/addon/services/admin-search-data-source.js index 7259e610f05cd..cfcc454d9bedc 100644 --- a/app/assets/javascripts/admin/addon/services/admin-search-data-source.js +++ b/app/assets/javascripts/admin/addon/services/admin-search-data-source.js @@ -17,7 +17,9 @@ const MAX_TYPE_RESULT_COUNT_HIGH = 50; const SEARCH_SCORES = { labelStart: 20, + labelPartial: 15, exactKeyword: 10, + partialKeyword: 7, fallback: 5, pageBonusScore: 20, }; @@ -268,7 +270,9 @@ export default class AdminSearchDataSource extends Service { } let filteredResults = []; - const escapedFilterRegExp = escapeRegExp(filter.toLowerCase()); + const escapedFilterRegExp = escapeRegExp( + filter.toLowerCase().trim().replace(/\s+/g, " ") + ); // Pointless to render heaps of settings if the filter is quite low. const perTypeLimit = @@ -277,9 +281,15 @@ export default class AdminSearchDataSource extends Service { : MAX_TYPE_RESULT_COUNT_HIGH; const labelStartRegex = new RegExp(`^${escapedFilterRegExp}`, "i"); + const labelPartialRegex = new RegExp(`\\b${escapedFilterRegExp}`, "i"); const exactKeywordRegexes = escapedFilterRegExp .split(" ") + .filter((keyword) => keyword.length > 3) .map((keyword) => new RegExp(`(${keyword})\\b`, "i")); + const partialKeywordRegexes = escapedFilterRegExp + .split(" ") + .filter((keyword) => keyword.length > 3) + .map((keyword) => new RegExp(`\\b${keyword}`, "i")); const fallbackRegex = new RegExp(`${escapedFilterRegExp}`, "i"); ADMIN_SEARCH_RESULT_TYPES.forEach((type) => { @@ -289,16 +299,27 @@ export default class AdminSearchDataSource extends Service { if (dataSourceItem.label.match(labelStartRegex)) { dataSourceItem.score += SEARCH_SCORES.labelStart; + } else if (dataSourceItem.label.match(labelPartialRegex)) { + dataSourceItem.score += SEARCH_SCORES.labelPartial; } if ( + exactKeywordRegexes.length > 0 && exactKeywordRegexes.every((regex) => { - return dataSourceItem.label.match(regex); + return dataSourceItem.keywords.match(regex); }) ) { dataSourceItem.score = dataSourceItem.score += SEARCH_SCORES.exactKeyword; + } else if ( + partialKeywordRegexes.length > 0 && + partialKeywordRegexes.every((regex) => { + return dataSourceItem.keywords.match(regex); + }) + ) { + dataSourceItem.score = dataSourceItem.score += + SEARCH_SCORES.partialKeyword; } - if (dataSourceItem.keywords.match(fallbackRegex)) { + if (filter.length > 3 && dataSourceItem.keywords.match(fallbackRegex)) { dataSourceItem.score += SEARCH_SCORES.fallback; } diff --git a/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js b/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js index ce61c29c731ef..590a78ca9ea92 100644 --- a/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js +++ b/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js @@ -142,8 +142,8 @@ module("Unit | Service | AdminSearchDataSource", function (hooks) { { description: "first page", icon: "house", - keywords: "exact setting", - label: "Page about exact setting", + keywords: "exact settings", + label: "Page about whatever", type: "page", url: "/admin", }, @@ -152,14 +152,14 @@ module("Unit | Service | AdminSearchDataSource", function (hooks) { { description: "first setting", icon: "house", - keywords: "exact setting", + keywords: "exact settings", label: "exact setting", type: "setting", url: "/admin", }, ]; - let results = this.subject.search("exact setting"); - assert.deepEqual(results[0].label, "Page about exact setting"); + let results = this.subject.search("exact setting"); + assert.deepEqual(results[0].label, "Page about whatever"); }); }); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 18a3428195f61..fd07d3a27003c 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -5373,6 +5373,7 @@ en: logo: title: "Logo" + header_description: "Configure the logos and icons used throughout your site" form: saved: "Logo settings are saved." logo: @@ -5437,6 +5438,7 @@ en: help_text: "recommended size is at least 280 x 150 pixels. Don't use an SVG image." fonts: title: "Fonts" + header_description: "Configure the fonts used throughout your site, including base font, heading font, and default text size" form: more_fonts: "More fonts" fewer_fonts: "Fewer fonts"