Compare commits
No commits in common. "921a72b015dbdda5623692974892f0d8d8efa6a3" and "282fd1be1349dee70174bba76be56b3233811255" have entirely different histories.
921a72b015
...
282fd1be13
11
README.md
11
README.md
|
@ -1,13 +1,10 @@
|
|||
> [!CAUTION]
|
||||
> This project is a heavy work-in-progress, there are bugs, and features may change or disappear.
|
||||
|
||||
# Locator for Obsidian
|
||||
|
||||
[](https://github.com/sponsors/scambier)
|
||||
|
||||
---
|
||||
|
||||
**Locator** is an Obsidian plugin that lets you locate your files in a few keystrokes. It is an experimental fork of Omnisearch.
|
||||
**Locator** is an Obsidian plugin that lets you locate your files in a few keystrokes. It is a lightweight, experimental version of Omnisearch.
|
||||
|
||||
It always instantly shows you the most relevant results, thanks to its smart weighting algorithm.
|
||||
|
||||
|
@ -42,13 +39,15 @@ You can check the [CHANGELOG](./CHANGELOG.md) for more information on the differ
|
|||
- Directly Insert a `[[link]]` from the search results
|
||||
- Supports Vim navigation keys
|
||||
|
||||
**Note:** support of Chinese depends
|
||||
on [this additional plugin](https://github.com/aidenlx/cm-chs-patch) (also you may need to clear search cache data to apply new Chinese index). Please read its documentation for more
|
||||
information.
|
||||
|
||||
## Issues & Feature Requests
|
||||
|
||||
If you're reading this README from the [repository's page](https://git.scambier.xyz/scambier/obsidian-locator), you'll notice it is hosted on a private forge without account registration.
|
||||
Locator is a personal hobby project, tailored for my own needs. It is publicly available because you may find it useful too, but I'm not interested in your issues or pull requests.
|
||||
|
||||
If you'd like to participate in a similar project (thank you!), I'll be glad to review your pull requests for [**Omnisearch**](https://github.com/scambier/obsidian-omnisearch)
|
||||
|
||||
Thank you for your understanding.
|
||||
|
||||
## LICENSE
|
||||
|
|
24
src/components/ResultItemInFile.svelte
Normal file
24
src/components/ResultItemInFile.svelte
Normal file
|
@ -0,0 +1,24 @@
|
|||
<script lang="ts">
|
||||
import type { ResultNote } from '../globals'
|
||||
import ResultItemContainer from './ResultItemContainer.svelte'
|
||||
import type LocatorPlugin from '../main'
|
||||
|
||||
export let plugin: LocatorPlugin
|
||||
export let offset: number
|
||||
export let note: ResultNote
|
||||
export let index = 0
|
||||
export let selected = false
|
||||
|
||||
$: cleanedContent = plugin.textProcessor.makeExcerpt(note?.content ?? '', offset)
|
||||
</script>
|
||||
|
||||
<ResultItemContainer
|
||||
id="{index.toString()}"
|
||||
on:auxclick
|
||||
on:click
|
||||
on:mousemove
|
||||
selected="{selected}">
|
||||
<div class="omnisearch-result__body">
|
||||
{@html plugin.textProcessor.highlightText(cleanedContent, note.matches)}
|
||||
</div>
|
||||
</ResultItemContainer>
|
|
@ -5,7 +5,7 @@ import { Notice } from 'obsidian'
|
|||
import type LocatorPlugin from './main'
|
||||
|
||||
export class Database extends Dexie {
|
||||
public static readonly dbVersion = 1
|
||||
public static readonly dbVersion = 10
|
||||
searchHistory!: Dexie.Table<{ id?: number; query: string }, number>
|
||||
minisearch!: Dexie.Table<
|
||||
{
|
||||
|
|
|
@ -190,16 +190,15 @@ export class SearchEngine {
|
|||
}
|
||||
const mtime = storedFields?.mtime as number
|
||||
const now = new Date().valueOf()
|
||||
const daysElapsed = (now - mtime) / (24 * 3600_000)
|
||||
const daysElapsed = (now - mtime) / (24 * 3600)
|
||||
|
||||
// Documents boost
|
||||
const cutoff = {
|
||||
[RecencyCutoff.Day]: -3,
|
||||
[RecencyCutoff.Week]: -0.3,
|
||||
[RecencyCutoff.Month]: -0.1,
|
||||
} as const
|
||||
return (
|
||||
1 + Math.exp(cutoff[settings.recencyBoost] * (daysElapsed / 1000))
|
||||
)
|
||||
return 1 + Math.exp(cutoff[settings.recencyBoost] * daysElapsed)
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { App, Plugin, PluginSettingTab, Setting } from 'obsidian'
|
||||
import { RecencyCutoff } from '../globals'
|
||||
import type LocatorPlugin from '../main'
|
||||
import { enableVerboseLogging } from '../tools/utils'
|
||||
import { injectSettingsBehavior } from './settings-behavior'
|
||||
import { injectSettingsDanger } from './settings-danger'
|
||||
import { injectSettingsHttp } from './settings-http'
|
||||
|
@ -63,6 +64,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||
.addToggle(toggle =>
|
||||
toggle.setValue(settings.verboseLogging).onChange(async v => {
|
||||
settings.verboseLogging = v
|
||||
enableVerboseLogging(v)
|
||||
await saveSettings(this.plugin)
|
||||
})
|
||||
)
|
||||
|
@ -135,5 +137,6 @@ export async function loadSettings(plugin: Plugin): Promise<LocatorSettings> {
|
|||
await plugin.loadData()
|
||||
)
|
||||
showExcerpt.set(settings.showExcerpt)
|
||||
enableVerboseLogging(settings.verboseLogging)
|
||||
return settings
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import {
|
|||
import { md5 } from 'pure-md5'
|
||||
import { eng, fra } from 'stopword'
|
||||
import { isSearchMatch, type SearchMatch } from '../globals'
|
||||
import { settings } from 'src/settings'
|
||||
|
||||
export function pathWithoutFilename(path: string): string {
|
||||
const split = path.split('/')
|
||||
|
@ -122,12 +121,11 @@ export function removeDiacritics(str: string, arabic = true): string {
|
|||
return ''
|
||||
}
|
||||
|
||||
// TODO: add a global setting to toggle this, this impacts performances
|
||||
if (arabic) {
|
||||
// Arabic diacritics
|
||||
// https://stackoverflow.com/a/40959537
|
||||
str = str
|
||||
// .replace(/([^\u0621-\u063A\u0641-\u064A\u0660-\u0669a-zA-Z 0-9])/g, '')
|
||||
.replace(/([^\u0621-\u063A\u0641-\u064A\u0660-\u0669a-zA-Z 0-9])/g, '')
|
||||
.replace(/(آ|إ|أ)/g, 'ا')
|
||||
.replace(/(ة)/g, 'ه')
|
||||
.replace(/(ئ|ؤ)/g, 'ء')
|
||||
|
@ -146,7 +144,6 @@ export function removeDiacritics(str: string, arabic = true): string {
|
|||
str = str.normalize('NFD').replace(diacriticsRegex, '').normalize('NFC')
|
||||
str = str.replaceAll('[__locator__backtick__]', '`')
|
||||
str = str.replaceAll('[__locator__caret__]', '^')
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
|
@ -253,8 +250,13 @@ export function warnVerbose(...args: any[]): void {
|
|||
printVerbose(console.warn, ...args)
|
||||
}
|
||||
|
||||
let verboseLoggingEnabled = false
|
||||
export function enableVerboseLogging(enable: boolean): void {
|
||||
verboseLoggingEnabled = enable
|
||||
}
|
||||
|
||||
function printVerbose(fn: (...args: any[]) => any, ...args: any[]): void {
|
||||
if (settings.verboseLogging) {
|
||||
if (verboseLoggingEnabled) {
|
||||
fn(...args)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user