Files
obsidian-tannersearch/README.md
Simon Cambier 1c3cc728f6 Squashed commit of the following:
commit 739f9c349031510e8ef010ba2445a2a1fdbec247
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 16:57:03 2022 +0200

    Code cleaning + README

commit 85762bae592f3eafd34ba22b0cf1841bfbd91ca6
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 14:59:01 2022 +0200

    Cleaning deleted PDFs from cache

commit 1a37bf38d3f64870d4b40df1b67d8106c893ab64
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sun Oct 16 13:18:06 2022 +0200

    PDF cache saved to IndexedDB
2022-10-16 16:58:10 +02:00

158 lines
6.3 KiB
Markdown

# Omnisearch for Obsidian
[![Sponsor me](https://img.shields.io/badge/%E2%9D%A4%20Like%20this%20plugin%3F-Sponsor%20me!-ff69b4)](https://github.com/sponsors/scambier)
![Obsidian plugin](https://img.shields.io/endpoint?url=https%3A%2F%2Fscambier.xyz%2Fobsidian-endpoints%2Fomnisearch.json)
![GitHub release (latest by date and asset)](https://img.shields.io/github/downloads/scambier/obsidian-omnisearch/latest/main.js)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/scambier/obsidian-omnisearch)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/scambier/obsidian-omnisearch?include_prereleases&label=BRAT%20beta)
**Omnisearch** is a search engine that "_just works_". It always instantly shows you the most relevant results, thanks to its smart weighting algorithm.
Under the hood, it uses the excellent [MiniSearch](https://github.com/lucaong/minisearch) library.
![](https://raw.githubusercontent.com/scambier/obsidian-omnisearch/master/images/omnisearch.gif)
## Features
- Automatic document scoring using the [BM25 algorithm](https://github.com/lucaong/minisearch/issues/129#issuecomment-1046257399)
- The relevance of a document against a query depends on the number of times the query terms appear in the document, its filename, and its headings
- Can search other plaintext files and PDFs (configurable in settings)
- Workflow similar to "Quick Switcher" plugins
- Keyboard first: you never have to use your mouse
- 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`
- Directly Insert a `[[link]]` from the search results
- Respects Obsidian's "Excluded Files" list - results are downranked, not hidden
- Optional support for Vim navigation keys (ctrl + j, k, n, p)
**Note:** support of Chinese, Japanese, Korean, etc. depends on [this additional plugin](https://github.com/aidenlx/cm-chs-patch). Please read its documentation for more information.
## Installation
- Omnisearch is available on [the official Community Plugins repository](https://obsidian.md/plugins?search=Omnisearch).
- Beta releases can be installed through [BRAT](https://github.com/TfTHacker/obsidian42-brat). **Be advised that those versions can be buggy.**
You can check the [CHANGELOG](./CHANGELOG.md) for more information on the different versions.
## Usage
Omnisearch can be used within 2 different contexts:
### Vault Search
Omnisearch's core feature, accessible with the Command Palette "**_Omnisearch: Vault search_**". This modal searches through your vault and returns the most relevant notes. That's all you need to _find_ a note.
If you want to list all the search matches of a single note, you can do so by using `tab` to open the In-File Search.
### In-File Search
Also accessible through the Command Palette "**_Omnisearch: In-file search_**". This modal searches through the active note's content and lists the matching results. Just press enter to automatically scroll to the right place.
## Public API
> This API is an experimental feature, the `ResultNote` interface may change in the future. The `search()` function returns at most 50 results.
If you're a plugin developer, you can use [this "plugin-api" package](https://github.com/vanakat/plugin-api), and get the api through `pluginApi('omnisearch')`.
Otherwise, you can access it with `app.plugins.plugins.omnisearch.api`.
```ts
// API:
{
// Returns a promise that will contain the same results as the Vault modal
search: (query: string) => Promise<ResultNote[]>
}
type ResultNoteApi = {
score: number
path: string
basename: string
foundWords: string[]
matches: SearchMatch[]
}
type SearchMatch = {
match: string
offset: number
}
```
### Dataview Integration
You can use the Omnisearch API directly within the [Dataview](https://blacksmithgu.github.io/obsidian-dataview/) plugin.
~~~js
```dataviewjs
const results = await app.plugins.plugins.omnisearch.api.search('your query')
const arr = dv.array(results).sort(r => r.score, 'desc')
dv.table(['File', 'Score'], arr.map(o => [dv.fileLink(o.path), Math.round(o.score)]))
```
~~~
## CSS Customization
There are several CSS classes you can use to customize the appearance of Omnisearch.
```css
.omnisearch-modal
.omnisearch-result
.omnisearch-result__title
.omnisearch-result__counter
.omnisearch-result__body
.omnisearch-highlight
.omnisearch-input-container
.omnisearch-input-field
```
For example, if you'd like the usual yellow highlight on search matches, you can add this code inside a CSS snippet file:
```css
.omnisearch-highlight {
color: var(--text-normal);
background-color: var(--text-highlight-bg);
}
```
See [styles.css](./assets/styles.css) for more information.
## Issues & Solutions
**Omnisearch makes Obsidian sluggish at startup.**
- You may have _big_ documents. Huge notes (like novels) can freeze the interface for a short time when being indexed. Enabling the setting "_Persist cache on disk_" may help you in this case.
**I have thousands of notes, and at startup I have to wait a few seconds before making a query, or else Omnisearch does not return all the expected results.**
- Enabling the setting "_Persist cache on disk_" may help you in this case.
**Omnisearch gives inconsistent/invalid results, or there are errors in the developer console.**
- Go in Omnisearch settings.
- If applicable, disable and re-enable "*Persist cache on disk*".
- Restart Obsidian to clear the cache and force a reindex.
**A query should return a result that does not appear.**
- If applicable, make sure that "*Ignore diacritics*" is enabled.
- If you have modified them, reset weightings to their original values.
- Rewrite your query and avoid numbers and common words.
**How do I highlight matches in search results?**
See [here](https://github.com/scambier/obsidian-omnisearch#css-customization).
**I'm still having an issue**
You can write your issue [here](https://github.com/scambier/obsidian-omnisearch/issues) with as much details as possible.
## LICENSE
Omnisearch is licensed under [GPL-3](https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)).
## Sponsors
![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)