This commit is contained in:
@@ -14,6 +14,9 @@ export const highlightClass = 'suggestion-highlight omnisearch-highlight'
|
|||||||
|
|
||||||
export const eventBus = new EventBus()
|
export const eventBus = new EventBus()
|
||||||
|
|
||||||
|
export const searchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
|
||||||
|
export const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
|
||||||
|
|
||||||
export type SearchNote = {
|
export type SearchNote = {
|
||||||
path: string
|
path: string
|
||||||
basename: string
|
basename: string
|
||||||
|
|||||||
24
src/notes.ts
24
src/notes.ts
@@ -1,10 +1,9 @@
|
|||||||
|
import { MarkdownView, TFile, type CachedMetadata } from 'obsidian'
|
||||||
import {
|
import {
|
||||||
MarkdownView,
|
notesCacheFilePath,
|
||||||
TFile,
|
type IndexedNote,
|
||||||
WorkspaceLeaf,
|
type ResultNote,
|
||||||
type CachedMetadata,
|
} from './globals'
|
||||||
} from 'obsidian'
|
|
||||||
import type { IndexedNote, ResultNote } from './globals'
|
|
||||||
import { stringsToRegex } from './utils'
|
import { stringsToRegex } from './utils'
|
||||||
import { settings } from './settings'
|
import { settings } from './settings'
|
||||||
|
|
||||||
@@ -15,8 +14,6 @@ import { settings } from './settings'
|
|||||||
*/
|
*/
|
||||||
export let notesCache: Record<string, IndexedNote> = {}
|
export let notesCache: Record<string, IndexedNote> = {}
|
||||||
|
|
||||||
const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
|
|
||||||
|
|
||||||
export function resetNotesCache(): void {
|
export function resetNotesCache(): void {
|
||||||
notesCache = {}
|
notesCache = {}
|
||||||
}
|
}
|
||||||
@@ -67,7 +64,11 @@ export async function openNote(
|
|||||||
let alreadyOpenAndPinned = false
|
let alreadyOpenAndPinned = false
|
||||||
app.workspace.iterateAllLeaves(leaf => {
|
app.workspace.iterateAllLeaves(leaf => {
|
||||||
if (leaf.view instanceof MarkdownView) {
|
if (leaf.view instanceof MarkdownView) {
|
||||||
if (!newPane && leaf.getViewState().state?.file === item.path && leaf.getViewState()?.pinned) {
|
if (
|
||||||
|
!newPane &&
|
||||||
|
leaf.getViewState().state?.file === item.path &&
|
||||||
|
leaf.getViewState()?.pinned
|
||||||
|
) {
|
||||||
app.workspace.setActiveLeaf(leaf, false, true)
|
app.workspace.setActiveLeaf(leaf, false, true)
|
||||||
alreadyOpenAndPinned = true
|
alreadyOpenAndPinned = true
|
||||||
}
|
}
|
||||||
@@ -95,7 +96,10 @@ export async function openNote(
|
|||||||
|
|
||||||
export async function createNote(name: string): Promise<void> {
|
export async function createNote(name: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const file = await app.vault.create(`${app.vault.getConfig('newFileFolderPath')}/${name}.md`, '')
|
const file = await app.vault.create(
|
||||||
|
`${app.vault.getConfig('newFileFolderPath')}/${name}.md`,
|
||||||
|
'',
|
||||||
|
)
|
||||||
await app.workspace.openLinkText(file.path, '')
|
await app.workspace.openLinkText(file.path, '')
|
||||||
const view = app.workspace.getActiveViewOfType(MarkdownView)
|
const view = app.workspace.getActiveViewOfType(MarkdownView)
|
||||||
if (!view) {
|
if (!view) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Notice, TAbstractFile, TFile } from 'obsidian'
|
|||||||
import MiniSearch, { type Options, type SearchResult } from 'minisearch'
|
import MiniSearch, { type Options, type SearchResult } from 'minisearch'
|
||||||
import {
|
import {
|
||||||
chsRegex,
|
chsRegex,
|
||||||
|
searchIndexFilePath,
|
||||||
SPACE_OR_PUNCTUATION,
|
SPACE_OR_PUNCTUATION,
|
||||||
type IndexedNote,
|
type IndexedNote,
|
||||||
type ResultNote,
|
type ResultNote,
|
||||||
@@ -33,7 +34,6 @@ import {
|
|||||||
|
|
||||||
let minisearchInstance: MiniSearch<IndexedNote>
|
let minisearchInstance: MiniSearch<IndexedNote>
|
||||||
let isIndexChanged: boolean
|
let isIndexChanged: boolean
|
||||||
const searchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
|
|
||||||
|
|
||||||
const tokenize = (text: string): string[] => {
|
const tokenize = (text: string): string[] => {
|
||||||
const tokens = text.split(SPACE_OR_PUNCTUATION)
|
const tokens = text.split(SPACE_OR_PUNCTUATION)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian'
|
import { Plugin, PluginSettingTab, Setting, SliderComponent } from 'obsidian'
|
||||||
|
import { notesCacheFilePath, searchIndexFilePath } from './globals'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
|
|
||||||
interface WeightingSettings {
|
interface WeightingSettings {
|
||||||
@@ -51,11 +52,15 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Ignore diacritics
|
// Ignore diacritics
|
||||||
|
const diacriticsDesc = new DocumentFragment()
|
||||||
|
diacriticsDesc.createSpan({}, span => {
|
||||||
|
span.innerHTML = `Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky".<br/>
|
||||||
|
<strong>Needs a restart to fully take effect.</strong>
|
||||||
|
`
|
||||||
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Ignore diacritics')
|
.setName('Ignore diacritics')
|
||||||
.setDesc(
|
.setDesc(diacriticsDesc)
|
||||||
'Normalize diacritics in search terms. Words like "brûlée" or "žluťoučký" will be indexed as "brulee" and "zlutoucky". Needs a restart to take effect.',
|
|
||||||
)
|
|
||||||
.addToggle(toggle =>
|
.addToggle(toggle =>
|
||||||
toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
|
toggle.setValue(settings.ignoreDiacritics).onChange(async v => {
|
||||||
settings.ignoreDiacritics = v
|
settings.ignoreDiacritics = v
|
||||||
@@ -63,13 +68,20 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const serializedIndexDesc = new DocumentFragment()
|
||||||
|
serializedIndexDesc.createSpan({}, span => {
|
||||||
|
span.innerHTML = `The search index is stored on disk, instead of being rebuilt at every startup. This results in faster loading times for bigger vaults and mobile devices.<br />
|
||||||
|
<em>⚠️ Note: the index can become corrupted - if you notice any issue, disable and re-enable this option to clear the cache.</em><br/>
|
||||||
|
<strong>Needs a restart to fully take effect.</strong>
|
||||||
|
`
|
||||||
|
})
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Store index in file')
|
.setName('EXPERIMENTAL - Store index in file')
|
||||||
.setDesc(
|
.setDesc(serializedIndexDesc)
|
||||||
'Index is stored on disk, instead of being rebuilt at every startup.',
|
|
||||||
)
|
|
||||||
.addToggle(toggle =>
|
.addToggle(toggle =>
|
||||||
toggle.setValue(settings.storeIndexInFile).onChange(async v => {
|
toggle.setValue(settings.storeIndexInFile).onChange(async v => {
|
||||||
|
app.vault.adapter.remove(notesCacheFilePath)
|
||||||
|
app.vault.adapter.remove(searchIndexFilePath)
|
||||||
settings.storeIndexInFile = v
|
settings.storeIndexInFile = v
|
||||||
await saveSettings(this.plugin)
|
await saveSettings(this.plugin)
|
||||||
}),
|
}),
|
||||||
@@ -173,7 +185,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||||||
|
|
||||||
export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
export const DEFAULT_SETTINGS: OmnisearchSettings = {
|
||||||
respectExcluded: true,
|
respectExcluded: true,
|
||||||
ignoreDiacritics: false,
|
ignoreDiacritics: true,
|
||||||
|
|
||||||
showIndexingNotices: false,
|
showIndexingNotices: false,
|
||||||
showShortName: false,
|
showShortName: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user