From e9c3e9414ec8695d3a5ec7e3a04c0f1c292f8424 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 8 Feb 2023 18:11:11 +0100 Subject: [PATCH 01/13] #107 - updated WIP layout --- assets/styles.css | 34 ++++++++++++-- src/components/ResultItemVault.svelte | 65 +++++++++++++++++++-------- src/settings.ts | 16 ------- src/tools/utils.ts | 6 +++ 4 files changed, 84 insertions(+), 37 deletions(-) diff --git a/assets/styles.css b/assets/styles.css index b9c3ac7..58b3254 100644 --- a/assets/styles.css +++ b/assets/styles.css @@ -4,10 +4,30 @@ .omnisearch-result { white-space: normal; display: flex; - flex-direction: column; + flex-direction: row; + justify-content: space-between; + flex-wrap: nowrap; +} + +.omnisearch-result__title-container { + display: flex; + align-items: center; + justify-content: space-between; + column-gap: 5px; + flex-wrap: wrap; } .omnisearch-result__title { + align-items: center; + display: flex; + gap: 5px; +} + +.omnisearch-result__folder-path { + font-size: 0.75rem; + align-items: center; + display: flex; + gap: 5px; } .omnisearch-result__counter { @@ -27,12 +47,20 @@ color: var(--text-muted); } +.omnisearch-result__image-container { + flex-basis: 20%; + text-align: right +} + .omnisearch-highlight { } .omnisearch-default-highlight { - color: var(--text-normal); - background-color: var(--text-highlight-bg); + text-decoration: underline; + text-decoration-color: var(--text-highlight-bg); + text-decoration-thickness: 3px; + text-underline-offset: -1px; + text-decoration-skip-ink: none; } .omnisearch-input-container { diff --git a/src/components/ResultItemVault.svelte b/src/components/ResultItemVault.svelte index 5e55589..94cd5e3 100644 --- a/src/components/ResultItemVault.svelte +++ b/src/components/ResultItemVault.svelte @@ -4,17 +4,24 @@ import { highlighter, isFileImage, + isFilePDF, makeExcerpt, + pathWithoutFilename, removeDiacritics, stringsToRegex, } from '../tools/utils' import ResultItemContainer from './ResultItemContainer.svelte' + import { onMount } from 'svelte' + import { setIcon } from 'obsidian' export let selected = false export let note: ResultNote let imagePath: string | null = null let title = '' + let notePath = '' + let folderPathIcon + let filePathIcon $: { imagePath = null @@ -31,10 +38,21 @@ $: cleanedContent = makeExcerpt(note.content, note.matches[0]?.offset ?? -1) $: glyph = false //cacheManager.getLiveDocument(note.path)?.doesNotExist $: { - title = settings.showShortName ? note.basename : note.path + title = note.basename + notePath = pathWithoutFilename(note.path) if (settings.ignoreDiacritics) { title = removeDiacritics(title) } + + // Icons + if (folderPathIcon) { + setIcon(folderPathIcon, 'folder-open') + } + if (filePathIcon) { + if (isFileImage(note.path)) setIcon(filePathIcon, 'file-image') + else if (isFilePDF(note.path)) setIcon(filePathIcon, 'file-line-chart') + else setIcon(filePathIcon, 'file-text') + } } @@ -44,31 +62,42 @@ on:click on:mousemove selected="{selected}"> -
-
-
- - {@html title.replace(reg, highlighter)} - +
+
+ + + {@html title.replace(reg, highlighter)} - {#if note.matches.length > 0} - - {note.matches.length} {note.matches.length > 1 - ? 'matches' - : 'match'} - - {/if} + + + + + + + + + + + +
+ + {notePath}
+
+
{#if $showExcerpt}
{@html cleanedContent.replace(reg, highlighter)}
{/if} -
- {#if imagePath} - - {/if} + + {#if imagePath} +
+ +
+ {/if} +
diff --git a/src/settings.ts b/src/settings.ts index 120c1e0..d2ed971 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -32,8 +32,6 @@ export interface OmnisearchSettings extends WeightingSettings { imagesIndexing: boolean /** Activate the small 🔍 button on Obsidian's ribbon */ ribbonIcon: boolean - /** Display short filenames in search results, instead of the full path */ - showShortName: boolean /** Display the small contextual excerpt in search results */ showExcerpt: boolean /** Render line returns with
in excerpts */ @@ -295,19 +293,6 @@ export class SettingsTab extends PluginSettingTab { }) ) - // Display note names without the full path - new Setting(containerEl) - .setName('Hide full path in results list') - .setDesc( - 'In the search results, only show the note name, without the full path.' - ) - .addToggle(toggle => - toggle.setValue(settings.showShortName).onChange(async v => { - settings.showShortName = v - await saveSettings(this.plugin) - }) - ) - // Highlight results new Setting(containerEl) .setName('Highlight matching words in results') @@ -390,7 +375,6 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = { PDFIndexing: false, imagesIndexing: false, - showShortName: false, ribbonIcon: true, showExcerpt: true, renderLineReturnInExcerpts: true, diff --git a/src/tools/utils.ts b/src/tools/utils.ts index fb392c9..1b2f7c2 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -43,6 +43,12 @@ export function removeFrontMatter(text: string): string { return text.replace(regexYaml, '') } +export function pathWithoutFilename(path: string): string { + const split = path.split('/') + split.pop() + return split.join('/') +} + export function wait(ms: number): Promise { return new Promise(resolve => { setTimeout(resolve, ms) From 48c9efcedc179a9be004ea67a36b0bcdc25b90be Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sat, 11 Feb 2023 10:42:01 +0100 Subject: [PATCH 02/13] #107 - new layout ok --- assets/styles.css | 3 +++ src/components/ResultItemVault.svelte | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/assets/styles.css b/assets/styles.css index 58b3254..00b8e05 100644 --- a/assets/styles.css +++ b/assets/styles.css @@ -28,10 +28,12 @@ align-items: center; display: flex; gap: 5px; + color: var(--text-muted); } .omnisearch-result__counter { font-size: 0.7rem; + color: var(--text-muted); } .omnisearch-result__body { @@ -45,6 +47,7 @@ -webkit-box-orient: vertical; color: var(--text-muted); + margin-left: 0.5em; } .omnisearch-result__image-container { diff --git a/src/components/ResultItemVault.svelte b/src/components/ResultItemVault.svelte index 94cd5e3..e30c234 100644 --- a/src/components/ResultItemVault.svelte +++ b/src/components/ResultItemVault.svelte @@ -62,27 +62,27 @@ on:click on:mousemove selected="{selected}"> -
+
{@html title.replace(reg, highlighter)} - - - - - - - + {#if note.matches.length > 0} + + {note.matches.length} {note.matches.length > 1 + ? 'matches' + : 'match'} + + {/if} +
- -
- - {notePath} -
+ +
+ + {notePath}
From 8c78c91cc3f919d077246f8f14160e99b8fe28e3 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sat, 11 Feb 2023 15:43:01 +0100 Subject: [PATCH 03/13] #154 - filter by file extension --- src/globals.ts | 1 + src/search/omnisearch.ts | 7 +++++++ src/search/query.ts | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/globals.ts b/src/globals.ts index 29c7013..a9e77fc 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -8,6 +8,7 @@ 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 regexExtensions = /(?:^|\s)\.(\w+)/g export const excerptBefore = 100 export const excerptAfter = 300 diff --git a/src/search/omnisearch.ts b/src/search/omnisearch.ts index fad8c51..53b5746 100644 --- a/src/search/omnisearch.ts +++ b/src/search/omnisearch.ts @@ -175,6 +175,13 @@ export class Omnisearch { }, }) + // Filter query results to only keep files that match query.extensions (if any) + if (query.extensions.length) { + results = results.filter(r => + query.extensions.some(e => r.id.endsWith(e)) + ) + } + // If the query does not return any result, // retry but with a shorter prefix limit if (!results.length) { diff --git a/src/search/query.ts b/src/search/query.ts index bbe595c..c11701b 100644 --- a/src/search/query.ts +++ b/src/search/query.ts @@ -1,6 +1,7 @@ import { settings } from '../settings' import { removeDiacritics, stripSurroundingQuotes } from '../tools/utils' import { parseQuery } from '../vendor/parse-query' +import { regexExtensions } from '../globals' type QueryToken = { /** @@ -20,8 +21,13 @@ type QueryToken = { export class Query { public segments: QueryToken[] = [] public exclusions: QueryToken[] = [] + public extensions: string[] = [] constructor(text = '') { + // Extract & remove extensions from the query + this.extensions = this.extractExtensions(text) + text = this.removeExtensions(text) + if (settings.ignoreDiacritics) text = removeDiacritics(text) const tokens = parseQuery(text.toLowerCase(), { tokenize: true }) this.exclusions = tokens.exclude.text @@ -59,4 +65,19 @@ export class Query { exact: stripped !== str, } } + + /** + * Extracts an array of extensions like ".png" from a string + */ + private extractExtensions(str: string): string[] { + const extensions = (str.match(regexExtensions) ?? []).map(o => o.trim()) + if (extensions) { + return extensions.map(ext => ext.toLowerCase()) + } + return [] + } + + private removeExtensions(str: string): string { + return str.replace(regexExtensions, '') + } } From c1d82dab54c84b7c53f80d44334dd94945a090ba Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sat, 11 Feb 2023 16:52:33 +0100 Subject: [PATCH 04/13] #141 - Added callback when indexing is done --- README.md | 8 ++++++-- src/main.ts | 3 ++- src/tools/api.ts | 31 ++++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f3cc4d1..d399d4f 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,13 @@ object `omnisearch` (`window.omnisearch`) ```ts // API: -{ +type OmnisearchApi = { // Returns a promise that will contain the same results as the Vault modal - search: (query: string) => Promise + search: (query: string) => Promise, + // Register a callback that will be called when the indexing is done + registerOnIndexed: (callback: () => void) => void, + // Unregister a callback that was previously registered + unregisterOnIndexed: (callback: () => void) => void, } type ResultNoteApi = { diff --git a/src/main.ts b/src/main.ts index 524bb73..039ea86 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,7 +17,7 @@ import { IndexingStepType, isCacheEnabled, } from './globals' -import api from './tools/api' +import api, { notifyOnIndexed } from './tools/api' import { isFileIndexable } from './tools/utils' import { database, OmnisearchCache } from './database' import * as NotesIndex from './notes-index' @@ -210,6 +210,7 @@ export default class OmnisearchPlugin extends Plugin { new Notice(`Omnisearch - Your files have been indexed.`) } indexingStep.set(IndexingStepType.Done) + notifyOnIndexed() } } diff --git a/src/tools/api.ts b/src/tools/api.ts index 577e90e..db5cc2c 100644 --- a/src/tools/api.ts +++ b/src/tools/api.ts @@ -17,6 +17,13 @@ export type SearchMatchApi = { offset: number } +let notified = false + +/** + * Callbacks to be called when the search index is ready + */ +let onIndexedCallbacks: Array<() => void> = [] + function mapResults(results: ResultNote[]): ResultNoteApi[] { return results.map(result => { const { score, path, basename, foundWords, matches, content } = result @@ -39,13 +46,27 @@ function mapResults(results: ResultNote[]): ResultNoteApi[] { }) } -async function search( - q: string, - options: Partial<{ excerpt: boolean }> = {} -): Promise { +async function search(q: string): Promise { const query = new Query(q) const raw = await searchEngine.getSuggestions(query) return mapResults(raw) } -export default { search } +function registerOnIndexed(cb: () => void): void { + onIndexedCallbacks.push(cb) + // Immediately call the callback if the indexing is already ready done + if (notified) { + cb() + } +} + +function unregisterOnIndexed(cb: () => void): void { + onIndexedCallbacks = onIndexedCallbacks.filter(o => o !== cb) +} + +export function notifyOnIndexed(): void { + notified = true + onIndexedCallbacks.forEach(cb => cb()) +} + +export default { search, registerOnIndexed, unregisterOnIndexed } From 088c3b77ac4d97885cdb2906d48e1d9363900174 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sat, 11 Feb 2023 17:27:03 +0100 Subject: [PATCH 05/13] #141 - added `refreshIndex()` to the public api --- src/tools/api.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/api.ts b/src/tools/api.ts index db5cc2c..440f6e8 100644 --- a/src/tools/api.ts +++ b/src/tools/api.ts @@ -2,6 +2,7 @@ import type { ResultNote } from '../globals' import { Query } from '../search/query' import { searchEngine } from '../search/omnisearch' import { makeExcerpt } from './utils' +import { refreshIndex } from '../notes-index' type ResultNoteApi = { score: number @@ -69,4 +70,4 @@ export function notifyOnIndexed(): void { onIndexedCallbacks.forEach(cb => cb()) } -export default { search, registerOnIndexed, unregisterOnIndexed } +export default { search, registerOnIndexed, unregisterOnIndexed, refreshIndex } From 7334af96185056cb256ab3cdaf010b03c2429246 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sat, 11 Feb 2023 17:27:24 +0100 Subject: [PATCH 06/13] 1.12.0 --- README.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d399d4f..c692430 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Under the hood, it uses the excellent [MiniSearch](https://github.com/lucaong/mi - Resistance to typos - Switch between Vault and In-file search to quickly skim multiple results in a single note - Supports `"expressions in quotes"` and `-exclusions` +- Filters file types with '.jpg' or '.md' - Directly Insert a `[[link]]` from the search results - Supports Vim navigation keys @@ -77,6 +78,8 @@ object `omnisearch` (`window.omnisearch`) type OmnisearchApi = { // Returns a promise that will contain the same results as the Vault modal search: (query: string) => Promise, + // Refreshes the index + refreshIndex: () => Promise // Register a callback that will be called when the indexing is done registerOnIndexed: (callback: () => void) => void, // Unregister a callback that was previously registered diff --git a/package.json b/package.json index 7c33c81..4185000 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scambier.obsidian-search", - "version": "1.11.1", + "version": "1.12.0", "description": "A search engine for Obsidian", "main": "dist/main.js", "scripts": { From f398034950bc40ec8dc140ca6a09a2bf1be09ca9 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Thu, 16 Feb 2023 18:00:57 +0100 Subject: [PATCH 07/13] #196 - Index the path --- src/search/omnisearch.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/search/omnisearch.ts b/src/search/omnisearch.ts index 53b5746..fbe3f0f 100644 --- a/src/search/omnisearch.ts +++ b/src/search/omnisearch.ts @@ -31,11 +31,22 @@ const tokenize = (text: string): string[] => { export class Omnisearch { public static readonly options: Options = { tokenize, + extractField: (doc, fieldName) => { + if (fieldName === 'folder') { + // return path without the filename + const parts = doc.path.split('/') + parts.pop() + return parts.join('/') + } + return (doc as any)[fieldName] + }, processTerm: (term: string) => (settings.ignoreDiacritics ? removeDiacritics(term) : term).toLowerCase(), idField: 'path', fields: [ 'basename', + // Different from `path`, since `path` is the unique index and needs to include the filename + 'folder', 'aliases', 'content', 'headings1', From ae08608e025f37a675c7a2f97cb6d54fee87abfd Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 19 Feb 2023 12:29:14 +0100 Subject: [PATCH 08/13] #107 #154 - Added file icon --- assets/styles.css | 5 ++++ src/components/ResultItemVault.svelte | 34 +++++++++++++++++---------- src/tools/utils.ts | 7 +++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/assets/styles.css b/assets/styles.css index 00b8e05..95fddc4 100644 --- a/assets/styles.css +++ b/assets/styles.css @@ -31,6 +31,11 @@ color: var(--text-muted); } +.omnisearch-result__extension { + font-size: 0.7rem; + color: var(--text-muted); + } + .omnisearch-result__counter { font-size: 0.7rem; color: var(--text-muted); diff --git a/src/components/ResultItemVault.svelte b/src/components/ResultItemVault.svelte index e30c234..afa5e6e 100644 --- a/src/components/ResultItemVault.svelte +++ b/src/components/ResultItemVault.svelte @@ -2,9 +2,12 @@ import { settings, showExcerpt } from 'src/settings' import type { ResultNote } from '../globals' import { + getExtension, highlighter, + isFileCanvas, isFileImage, isFilePDF, + isFilePlaintext, makeExcerpt, pathWithoutFilename, removeDiacritics, @@ -20,8 +23,8 @@ let imagePath: string | null = null let title = '' let notePath = '' - let folderPathIcon - let filePathIcon + let elFolderPathIcon: HTMLElement + let elFilePathIcon: HTMLElement $: { imagePath = null @@ -45,13 +48,14 @@ } // Icons - if (folderPathIcon) { - setIcon(folderPathIcon, 'folder-open') + if (elFolderPathIcon) { + setIcon(elFolderPathIcon, 'folder-open') } - if (filePathIcon) { - if (isFileImage(note.path)) setIcon(filePathIcon, 'file-image') - else if (isFilePDF(note.path)) setIcon(filePathIcon, 'file-line-chart') - else setIcon(filePathIcon, 'file-text') + if (elFilePathIcon) { + if (isFileImage(note.path)) setIcon(elFilePathIcon, 'image') + else if (isFilePDF(note.path)) setIcon(elFilePathIcon, 'file-text') + else if (isFileCanvas(note.path)) setIcon(elFilePathIcon, 'layout-dashboard') + else setIcon(elFilePathIcon, 'file') } } @@ -65,8 +69,10 @@
- + {@html title.replace(reg, highlighter)} + .{getExtension(note.path)} {#if note.matches.length > 0} @@ -80,10 +86,12 @@
-
- - {notePath} -
+ {#if notePath} +
+ + {notePath} +
+ {/if}
{#if $showExcerpt} diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 1b2f7c2..82470bd 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -255,13 +255,12 @@ export function isFileIndexable(path: string): boolean { } export function isFileImage(path: string): boolean { - return ( - path.endsWith('.png') || path.endsWith('.jpg') || path.endsWith('.jpeg') - ) + const ext = getExtension(path) + return (ext === 'png' || ext === 'jpg' || ext === 'jpeg') } export function isFilePDF(path: string): boolean { - return path.endsWith('.pdf') + return getExtension(path) === 'pdf' } export function isFilePlaintext(path: string): boolean { From c70e446e8446afacccadb9aecb67a7b4d920e12b Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 19 Feb 2023 14:03:16 +0100 Subject: [PATCH 09/13] #195 - Fixed highlighting for cyrillic chars --- src/components/ResultItemInFile.svelte | 14 +++++++++++--- src/components/ResultItemVault.svelte | 11 +++++------ src/tools/utils.ts | 21 ++++++++++++++------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/components/ResultItemInFile.svelte b/src/components/ResultItemInFile.svelte index 3f35c51..3dcba2e 100644 --- a/src/components/ResultItemInFile.svelte +++ b/src/components/ResultItemInFile.svelte @@ -1,6 +1,10 @@ - +
- {@html cleanedContent.replace(reg, highlighter)} + {@html cleanedContent.replace(reg, highlighterGroups)}
diff --git a/src/components/ResultItemVault.svelte b/src/components/ResultItemVault.svelte index afa5e6e..13a287b 100644 --- a/src/components/ResultItemVault.svelte +++ b/src/components/ResultItemVault.svelte @@ -3,18 +3,16 @@ import type { ResultNote } from '../globals' import { getExtension, - highlighter, + highlighterGroups, isFileCanvas, isFileImage, isFilePDF, - isFilePlaintext, makeExcerpt, pathWithoutFilename, removeDiacritics, stringsToRegex, } from '../tools/utils' import ResultItemContainer from './ResultItemContainer.svelte' - import { onMount } from 'svelte' import { setIcon } from 'obsidian' export let selected = false @@ -54,7 +52,8 @@ if (elFilePathIcon) { if (isFileImage(note.path)) setIcon(elFilePathIcon, 'image') else if (isFilePDF(note.path)) setIcon(elFilePathIcon, 'file-text') - else if (isFileCanvas(note.path)) setIcon(elFilePathIcon, 'layout-dashboard') + else if (isFileCanvas(note.path)) + setIcon(elFilePathIcon, 'layout-dashboard') else setIcon(elFilePathIcon, 'file') } } @@ -70,7 +69,7 @@
- {@html title.replace(reg, highlighter)} + {@html title.replace(reg, highlighterGroups)} .{getExtension(note.path)} @@ -96,7 +95,7 @@
{#if $showExcerpt}
- {@html cleanedContent.replace(reg, highlighter)} + {@html cleanedContent.replace(reg, highlighterGroups)}
{/if} diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 82470bd..00e0666 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -15,6 +15,7 @@ import { regexLineSplit, regexStripQuotes, regexYaml, + SPACE_OR_PUNCTUATION, type SearchMatch, } from '../globals' import { settings } from '../settings' @@ -25,6 +26,8 @@ export function highlighter(str: string): string { return `${str}` } +export const highlighterGroups = `$1$2` + export function escapeHTML(html: string): string { return html .replaceAll('&', '&') @@ -78,12 +81,16 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] { */ export function stringsToRegex(strings: string[]): RegExp { if (!strings.length) return /^$/g - // \\b is "word boundary", and is not applied if the user uses the cm-chs-patch plugin - const joined = strings - .map(s => (getChsSegmenter() ? '' : '\\b') + escapeRegex(s)) - .join('|') - const reg = new RegExp(`(${joined})`, 'gi') - // console.log(reg) + // Default word split is not applied if the user uses the cm-chs-patch plugin + const joined = + '(' + + (getChsSegmenter() ? '' : SPACE_OR_PUNCTUATION.source) + + ')' + + '(' + + strings.map(s => escapeRegex(s)).join('|') + + ')' + + const reg = new RegExp(`${joined}`, 'giu') return reg } @@ -256,7 +263,7 @@ export function isFileIndexable(path: string): boolean { export function isFileImage(path: string): boolean { const ext = getExtension(path) - return (ext === 'png' || ext === 'jpg' || ext === 'jpeg') + return ext === 'png' || ext === 'jpg' || ext === 'jpeg' } export function isFilePDF(path: string): boolean { From 46e22d175645f75bce5356c5a9bfc71fc401a365 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Mon, 20 Feb 2023 17:35:09 +0100 Subject: [PATCH 10/13] #195 - Fixed issue where $1 & $2 were shown as-is in case of no content to replace --- src/tools/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 00e0666..9254408 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -26,7 +26,11 @@ export function highlighter(str: string): string { return `${str}` } -export const highlighterGroups = `$1$2` +export function highlighterGroups(...args: any[]) { + if (args[1] && args[2]) + return `${args[1]}${args[2]}` + return '<no content>' +} export function escapeHTML(html: string): string { return html From dd48e875172c8bc316db8db234a83f275677656a Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Mon, 20 Feb 2023 18:00:31 +0100 Subject: [PATCH 11/13] #195 - Also highlight single emojis --- src/search/omnisearch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search/omnisearch.ts b/src/search/omnisearch.ts index fbe3f0f..963a0b3 100644 --- a/src/search/omnisearch.ts +++ b/src/search/omnisearch.ts @@ -366,7 +366,7 @@ export class Omnisearch { // Tags, starting with # ...tags, - ].filter(w => w.length > 1) + ].filter(w => w.length > 1 || /\p{Emoji}/u.test(w)) // console.log(foundWords) const matches = this.getMatches( From 4f21377aed038247ff3c99c814f4b6c6422176c9 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Mon, 20 Feb 2023 18:03:13 +0100 Subject: [PATCH 12/13] 1.12.1-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4185000..4d604b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scambier.obsidian-search", - "version": "1.12.0", + "version": "1.12.1-beta.1", "description": "A search engine for Obsidian", "main": "dist/main.js", "scripts": { From 4df09aa70cafb509cd31287744ef2843b5f2fcc1 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Fri, 24 Feb 2023 10:56:24 +0100 Subject: [PATCH 13/13] #196 - Added customizable weighting for note's directory --- src/search/omnisearch.ts | 5 +++-- src/settings.ts | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/search/omnisearch.ts b/src/search/omnisearch.ts index 963a0b3..c9a3421 100644 --- a/src/search/omnisearch.ts +++ b/src/search/omnisearch.ts @@ -32,7 +32,7 @@ export class Omnisearch { public static readonly options: Options = { tokenize, extractField: (doc, fieldName) => { - if (fieldName === 'folder') { + if (fieldName === 'directory') { // return path without the filename const parts = doc.path.split('/') parts.pop() @@ -46,7 +46,7 @@ export class Omnisearch { fields: [ 'basename', // Different from `path`, since `path` is the unique index and needs to include the filename - 'folder', + 'directory', 'aliases', 'content', 'headings1', @@ -179,6 +179,7 @@ export class Omnisearch { combineWith: 'AND', boost: { basename: settings.weightBasename, + directory: settings.weightDirectory, aliases: settings.weightBasename, headings1: settings.weightH1, headings2: settings.weightH2, diff --git a/src/settings.ts b/src/settings.ts index d2ed971..f3778a0 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -12,6 +12,7 @@ import type OmnisearchPlugin from './main' interface WeightingSettings { weightBasename: number + weightDirectory: number weightH1: number weightH2: number weightH3: number @@ -318,6 +319,10 @@ export class SettingsTab extends PluginSettingTab { ) .addSlider(cb => this.weightSlider(cb, 'weightBasename')) + new Setting(containerEl) + .setName(`File directory (default: ${DEFAULT_SETTINGS.weightDirectory})`) + .addSlider(cb => this.weightSlider(cb, 'weightDirectory')) + new Setting(containerEl) .setName(`Headings level 1 (default: ${DEFAULT_SETTINGS.weightH1})`) .addSlider(cb => this.weightSlider(cb, 'weightH1')) @@ -383,7 +388,8 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = { showPreviousQueryResults: true, simpleSearch: false, - weightBasename: 2, + weightBasename: 3, + weightDirectory: 2, weightH1: 1.5, weightH2: 1.3, weightH3: 1.1,