From b7242fbee4f4d4e32a2d2c7f8c327d73526ddd60 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 4 May 2022 20:34:56 +0200 Subject: [PATCH] Moved a var --- src/globals.ts | 1 + src/search.ts | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/globals.ts b/src/globals.ts index e7ba6a8..f1c65e1 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -5,6 +5,7 @@ export const regexWikilink = /^!?\[\[(?.+?)(\|(?.+?))?\]\]/ 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 excerptBefore = 100 export const excerptAfter = 180 diff --git a/src/search.ts b/src/search.ts index 6d7a9f0..e5d9941 100644 --- a/src/search.ts +++ b/src/search.ts @@ -1,6 +1,7 @@ import { Notice, TFile, type TAbstractFile } from 'obsidian' import MiniSearch, { type SearchResult } from 'minisearch' import { + chsRegex, SPACE_OR_PUNCTUATION, type IndexedNote, type ResultNote, @@ -17,15 +18,13 @@ import type { Query } from './query' let minisearchInstance: MiniSearch let indexedNotes: Record = {} -const chsPattern = /[\u4e00-\u9fa5]/ - 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 => - chsPattern.test(word) ? chsSegmenter.cut(word) : [word], + chsRegex.test(word) ? chsSegmenter.cut(word) : [word], ) } else return tokens