diff --git a/src/search/omnisearch.ts b/src/search/omnisearch.ts index c9a3421..a057604 100644 --- a/src/search/omnisearch.ts +++ b/src/search/omnisearch.ts @@ -10,6 +10,7 @@ import { settings } from '../settings' import { chunkArray, removeDiacritics, + splitCamelCase, stringsToRegex, stripMarkdownCharacters, } from '../tools/utils' @@ -25,7 +26,7 @@ const tokenize = (text: string): string[] => { return tokens.flatMap(word => chsRegex.test(word) ? chsSegmenter.cut(word) : [word] ) - } else return tokens + } else return tokens.flatMap(splitCamelCase) } export class Omnisearch { diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 9254408..66ee8d2 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -307,3 +307,11 @@ export function chunkArray(arr: T[], len: number): T[][] { return chunks } + +/** + * Converts a 'fooBarBAZLorem' into ['foo', 'Bar', 'BAZ', 'Lorem] + * @param text + */ +export function splitCamelCase(text: string): string[] { + return text.replace(/([a-z](?=[A-Z]))/g, '$1 ').split(' ') +}