diff --git a/src/globals.ts b/src/globals.ts index acd2f94..756e9ae 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -6,6 +6,7 @@ export const regexLineSplit = /\r?\n|\r|((\.|\?|!)( |\r?\n|\r))/g export const regexYaml = /^---\s*\n(.*?)\n?^---\s?/ms export const regexStripQuotes = /^"|"$|^'|'$/g export const chsRegex = /[\u4e00-\u9fa5]/ +export const chsSegmenter = (app as any).plugins.plugins['cm-chs-patch'] export const excerptBefore = 100 export const excerptAfter = 300 diff --git a/src/search/omnisearch.ts b/src/search/omnisearch.ts index 30c41da..a7314ba 100644 --- a/src/search/omnisearch.ts +++ b/src/search/omnisearch.ts @@ -7,6 +7,7 @@ import type { } from '../globals' import { chsRegex, + chsSegmenter, indexingStep, IndexingStepType, SPACE_OR_PUNCTUATION, @@ -24,7 +25,6 @@ import { cacheManager } from '../cache-manager' const tokenize = (text: string): string[] => { const tokens = text.split(SPACE_OR_PUNCTUATION) - const chsSegmenter = (app as any).plugins.plugins['cm-chs-patch'] if (chsSegmenter) { return tokens.flatMap(word => diff --git a/src/tools/utils.ts b/src/tools/utils.ts index a986bde..8f62702 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -7,6 +7,7 @@ import { } from 'obsidian' import type { SearchMatch } from '../globals' import { + chsSegmenter, excerptAfter, excerptBefore, highlightClass, @@ -70,7 +71,10 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] { */ export function stringsToRegex(strings: string[]): RegExp { if (!strings.length) return /^$/g - const joined = strings.map(s => '\\b' + escapeRegex(s)).join('|') + // \\b is "word boundary", and is not applied if the user uses the cm-chs-patch plugin + const joined = strings + .map(s => (chsSegmenter ? '' : '\\b') + escapeRegex(s)) + .join('|') const reg = new RegExp(`(${joined})`, 'gi') // console.log(reg) return reg