Merge branch 'master' of https://github.com/scambier/obsidian-omnisearch
This commit is contained in:
@@ -103,7 +103,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
if (isFileIndexable(file.path)) {
|
||||
logDebug('Renaming file', file.path)
|
||||
cacheManager.removeFromLiveCache(oldPath)
|
||||
cacheManager.addToLiveCache(file.path)
|
||||
await cacheManager.addToLiveCache(file.path)
|
||||
searchEngine.removeFromPaths([oldPath])
|
||||
await searchEngine.addFromPaths([file.path])
|
||||
}
|
||||
@@ -206,14 +206,14 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
|
||||
// Disable settings.useCache while writing the cache, in case it freezes
|
||||
settings.useCache = false
|
||||
saveSettings(this)
|
||||
await saveSettings(this)
|
||||
|
||||
// Write the cache
|
||||
await searchEngine.writeToCache()
|
||||
|
||||
// Re-enable settings.caching
|
||||
settings.useCache = true
|
||||
saveSettings(this)
|
||||
await saveSettings(this)
|
||||
}
|
||||
|
||||
console.timeEnd('Omnisearch - Indexing total time')
|
||||
|
||||
@@ -43,7 +43,7 @@ export async function refreshIndex(): Promise<void> {
|
||||
const paths = [...notesToReindex].map(n => n.path)
|
||||
if (paths.length) {
|
||||
searchEngine.removeFromPaths(paths)
|
||||
searchEngine.addFromPaths(paths)
|
||||
await searchEngine.addFromPaths(paths)
|
||||
notesToReindex.clear()
|
||||
// console.log(`Omnisearch - Reindexed ${paths.length} file(s)`)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,12 @@ import { sortBy } from 'lodash-es'
|
||||
const tokenize = (text: string): string[] => {
|
||||
let tokens = text.split(SPACE_OR_PUNCTUATION)
|
||||
|
||||
// Split hyphenated tokens
|
||||
tokens = [...tokens, ...tokens.flatMap(splitHyphens)]
|
||||
|
||||
// Split camelCase tokens into "camel" and "case
|
||||
tokens = [...tokens, ...tokens.flatMap(splitCamelCase)]
|
||||
|
||||
// When enabled, we only use the chsSegmenter,
|
||||
// and not the other custom tokenizers
|
||||
const chsSegmenter = getChsSegmenter()
|
||||
@@ -32,12 +38,8 @@ const tokenize = (text: string): string[] => {
|
||||
tokens = tokens.flatMap(word =>
|
||||
chsRegex.test(word) ? chsSegmenter.cut(word) : [word]
|
||||
)
|
||||
} else {
|
||||
// Split camelCase tokens into "camel" and "case
|
||||
tokens = [...tokens, ...tokens.flatMap(splitCamelCase)]
|
||||
// Split hyphenated tokens
|
||||
tokens = [...tokens, ...tokens.flatMap(splitHyphens)]
|
||||
}
|
||||
|
||||
return tokens
|
||||
}
|
||||
|
||||
|
||||
@@ -507,9 +507,9 @@ export class SettingsTab extends PluginSettingTab {
|
||||
cb.setLimits(1, 5, 0.1)
|
||||
.setValue(settings[key])
|
||||
.setDynamicTooltip()
|
||||
.onChange(v => {
|
||||
.onChange(async (v) => {
|
||||
settings[key] = v
|
||||
saveSettings(this.plugin)
|
||||
await saveSettings(this.plugin)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,14 +342,15 @@ export function chunkArray<T>(arr: T[], len: number): T[][] {
|
||||
* @param text
|
||||
*/
|
||||
export function splitCamelCase(text: string): string[] {
|
||||
const split = text
|
||||
// if no camel case found, do nothing
|
||||
if (!/[a-z][A-Z]/.test(text)) {
|
||||
return [];
|
||||
}
|
||||
const splittedText = text
|
||||
.replace(/([a-z](?=[A-Z]))/g, '$1 ')
|
||||
.split(' ')
|
||||
.filter(t => t)
|
||||
if (split.length > 1) {
|
||||
return split
|
||||
}
|
||||
return []
|
||||
.filter(t => t);
|
||||
return splittedText;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user