mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-13 16:22:32 +10:00
added fuzzy matching logic for menu search
This commit is contained in:
@ -264,10 +264,20 @@ export const getSuggestionItems = ({
|
|||||||
const search = query.toLowerCase();
|
const search = query.toLowerCase();
|
||||||
const filteredGroups: SlashMenuGroupedItemsType = {};
|
const filteredGroups: SlashMenuGroupedItemsType = {};
|
||||||
|
|
||||||
|
const fuzzyMatch = (query, target) => {
|
||||||
|
let queryIndex = 0;
|
||||||
|
target = target.toLowerCase();
|
||||||
|
for (let char of target) {
|
||||||
|
if (query[queryIndex] === char) queryIndex++;
|
||||||
|
if (queryIndex === query.length) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
for (const [group, items] of Object.entries(CommandGroups)) {
|
for (const [group, items] of Object.entries(CommandGroups)) {
|
||||||
const filteredItems = items.filter((item) => {
|
const filteredItems = items.filter((item) => {
|
||||||
return (
|
return (
|
||||||
item.title.toLowerCase().includes(search) ||
|
fuzzyMatch(search, item.title) ||
|
||||||
item.description.toLowerCase().includes(search) ||
|
item.description.toLowerCase().includes(search) ||
|
||||||
(item.searchTerms &&
|
(item.searchTerms &&
|
||||||
item.searchTerms.some((term: string) => term.includes(search)))
|
item.searchTerms.some((term: string) => term.includes(search)))
|
||||||
|
|||||||
Reference in New Issue
Block a user