Moved a var

This commit is contained in:
Simon Cambier
2022-05-04 20:34:56 +02:00
parent 7fcac79b77
commit b7242fbee4
2 changed files with 3 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ export const regexWikilink = /^!?\[\[(?<name>.+?)(\|(?<alias>.+?))?\]\]/
export const regexLineSplit = /\r?\n|\r|((\.|\?|!)( |\r?\n|\r))/g export const regexLineSplit = /\r?\n|\r|((\.|\?|!)( |\r?\n|\r))/g
export const regexYaml = /^---\s*\n(.*?)\n?^---\s?/ms export const regexYaml = /^---\s*\n(.*?)\n?^---\s?/ms
export const regexStripQuotes = /^"|"$|^'|'$/g export const regexStripQuotes = /^"|"$|^'|'$/g
export const chsRegex = /[\u4e00-\u9fa5]/
export const excerptBefore = 100 export const excerptBefore = 100
export const excerptAfter = 180 export const excerptAfter = 180

View File

@@ -1,6 +1,7 @@
import { Notice, TFile, type TAbstractFile } from 'obsidian' import { Notice, TFile, type TAbstractFile } from 'obsidian'
import MiniSearch, { type SearchResult } from 'minisearch' import MiniSearch, { type SearchResult } from 'minisearch'
import { import {
chsRegex,
SPACE_OR_PUNCTUATION, SPACE_OR_PUNCTUATION,
type IndexedNote, type IndexedNote,
type ResultNote, type ResultNote,
@@ -17,15 +18,13 @@ import type { Query } from './query'
let minisearchInstance: MiniSearch<IndexedNote> let minisearchInstance: MiniSearch<IndexedNote>
let indexedNotes: Record<string, IndexedNote> = {} let indexedNotes: Record<string, IndexedNote> = {}
const chsPattern = /[\u4e00-\u9fa5]/
const tokenize = (text: string): string[] => { const tokenize = (text: string): string[] => {
const tokens = text.split(SPACE_OR_PUNCTUATION) const tokens = text.split(SPACE_OR_PUNCTUATION)
const chsSegmenter = (app as any).plugins.plugins['cm-chs-patch'] const chsSegmenter = (app as any).plugins.plugins['cm-chs-patch']
if (chsSegmenter) { if (chsSegmenter) {
return tokens.flatMap(word => return tokens.flatMap(word =>
chsPattern.test(word) ? chsSegmenter.cut(word) : [word], chsRegex.test(word) ? chsSegmenter.cut(word) : [word],
) )
} }
else return tokens else return tokens