DEV: Tighten up fuzzy search site setting results (#23176)

Sometimes the fuzzy search would return too many site setting results
making it hard to find what you are searching for. This change still
allows for fuzzy searching but tightens up the criteria for being a
fuzzy match.

One example is searching for 'cheer', a term associated with a plugin,
previously returned ~55 search results. With this change it will return
~13 (Actual numbers depend on how many plugins your instance has).

Another example is searching for 'digest'. Previously returned ~37
results and now will return ~14.

Follow up to: e63e193a0a

See also: https://meta.discourse.org/t/276013
This commit is contained in:
Blake Erickson 2023-08-21 19:04:57 -06:00 committed by GitHub
parent 742d71e99c
commit 26b3c63c74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -79,7 +79,15 @@ export default class AdminSiteSettingsController extends Controller {
item.get("description").toLowerCase().includes(filter) ||
(item.get("value") || "").toString().toLowerCase().includes(filter);
if (!filterResult && fuzzyRegex && fuzzyRegex.test(setting)) {
fuzzyMatches.push(item);
// Tightens up fuzzy search results a bit.
const fuzzySearchLimiter = 15;
const strippedSetting = setting.replace(/[^a-z0-9]/gi, "");
if (
strippedSetting.length <=
strippedQuery.length + fuzzySearchLimiter
) {
fuzzyMatches.push(item);
}
}
return filterResult;
} else {

View File

@ -30,6 +30,16 @@ module("Unit | Controller | admin-site-settings", function (hooks) {
value: "",
setting: "hello world",
}),
SiteSetting.create({
description: "",
value: "",
setting: "digest_logo",
}),
SiteSetting.create({
description: "",
value: "",
setting: "pending_users_reminder_delay_minutes",
}),
],
},
];
@ -38,5 +48,8 @@ module("Unit | Controller | admin-site-settings", function (hooks) {
assert.deepEqual(results[0].siteSettings.length, 2);
// ensures hello world shows up before fuzzy hpello world
assert.deepEqual(results[0].siteSettings[0].setting, "hello world");
results = controller.performSearch("digest", settings2);
assert.deepEqual(results[0].siteSettings.length, 1);
assert.deepEqual(results[0].siteSettings[0].setting, "digest_logo");
});
});