A search index and more for your markdown notes
MIT License
A search index and more for your markdown notes.
search-notes highlands basic text search
search-notes name:wallace search yaml frontmatter
search-notes "tag:royalty britain" multiple terms
search-notes "brit*" prefix search
search-notes "scatlond~1" fuzzy search
search-notes "tags:stuart -france" exclude terms
search-notes "tags:stuart +france" boolean AND
search-notes "britain^2 france^1" boost terms
% search-notes "scot* +tags:stuart" -d ./test/notes
Search took 0.017599736 seconds
┌─────────┬─────────────────────┬─────────┬────────────────────────────────────────────┐
│ (index) │ File │ Score │ Hits │
├─────────┼─────────────────────┼─────────┼────────────────────────────────────────────┤
│ 0 │ 'prince-charlie.md' │ '0.221' │ '"scotland" (body, tags), "stuart" (tags)' │
│ 1 │ 'queen-anne.md' │ '0.189' │ '"scotland" (body), "stuart" (tags)' │
└─────────┴─────────────────────┴─────────┴────────────────────────────────────────────┘
Zero-install: use npx to download and run
npx search-notes query
Global:
npm install -g local-notes
search-notes query
Parses YML frontmatter into structured data you can query.
---
title: Scottish History
year: 2020
---
# Scottish History
This is the body of the post.
You can query it using fuzzy search.
search-notes "title:scottish year:202* past~1"
Hashtags are #indexed so you can #query them
search-notes tags:something
Outgoing links are indexed, so you can look up "backlinks" (incoming links) by searching what links to a file. You can look up any link this way, not just local documents. E.g., you can find all documents that link to Wikipedia.
# Find all documents that link to a page
search-notes -d test/notes "linksTo:SomePage"
# See all links
search-notes -d test/notes "linksTo:\*"
The --graph
(-g
) option produces a Mermaid diagram of the entity relationships in your files. Right now this is tags and links.
search-notes --graph
flowchart LR;
'james-stuart.md'(["James Francis Edward Stuart"]) --> 'pretender.md'
tags_pretender[#pretender] -.- 'james-stuart.md'(["James Francis Edward Stuart"])
tags_pretender[#pretender] -.- 'pretender.md'(["pretender.md"])
'prince-charlie.md'(["Bonnie Prince Charlie"]) --> 'james-stuart.md'
'prince-charlie.md'(["Bonnie Prince Charlie"]) --> 'pretender.md'
tags_stuart[#stuart] -.- 'prince-charlie.md'(["Bonnie Prince Charlie"])
tags_royal[#royal] -.- 'prince-charlie.md'(["Bonnie Prince Charlie"])
tags_scotland[#scotland] -.- 'prince-charlie.md'(["Bonnie Prince Charlie"])
tags_france[#france] -.- 'prince-charlie.md'(["Bonnie Prince Charlie"])
tags_monarch[#monarch] -.- 'prince-charlie.md'(["Bonnie Prince Charlie"])
tags_highlands[#highlands] -.- 'prince-charlie.md'(["Bonnie Prince Charlie"])
tags_pretender[#pretender] -.- 'prince-charlie.md'(["Bonnie Prince Charlie"])
tags_stuart[#stuart] -.- 'queen-anne.md'(["Queen Anne"])
tags_royal[#royal] -.- 'queen-anne.md'(["Queen Anne"])
tags_britain[#britain] -.- 'queen-anne.md'(["Queen Anne"])
subgraph Tags
tags_pretender[#pretender]
tags_pretender[#pretender]
tags_stuart[#stuart]
tags_royal[#royal]
tags_scotland[#scotland]
tags_france[#france]
tags_monarch[#monarch]
tags_highlands[#highlands]
tags_pretender[#pretender]
tags_stuart[#stuart]
tags_royal[#royal]
tags_britain[#britain]
end
You can turn the chart into an image or PDF using Mermaid's CLI.
If you have @mermaid-js/mermaid-cli
installed globally:
search-notes --graph > graph.mmd | mmdc -i graph.mmd -o graph.png
If you have npx
:
search-notes --graph > graph.mmd | npx -p @mermaid-js/mermaid-cli mmdc -i graph.mmd -o graph.png
search-notes --help
search-notes [query]
Search for notes using structured data and full text index, with fuzzy matching.
Positionals:
query text to search for [string] [default: ""]
Options:
--directory, -d directory to search in [string] [default: ""]
--cache, -c cached search index to use (ignored if file doesn't exist) [string] [default: "search.json"]
--write-cache, -w create or update search index cache file [boolean] [default: false]
--explain show relevance score and other details for results [boolean] [default: true]
--version Show version number [boolean]
--help Show help [boolean]
Examples:
search-notes highlands basic text search
search-notes name:wallace search yaml frontmatter
search-notes "tags:royalty britain" multiple terms
search-notes "brit*" prefix search
search-notes "scatlond~1" fuzzy search
search-notes "scatlonz~2" fuzzier search
search-notes "tags:stuart -france" negate term
search-notes "tags:stuart +france" boolean AND
search-notes "britain^2 france^1" boost term relevance
search-notes "linksTo:filename" incoming links
search-notes --graph create node graph in mmd format
search-notes -w re-index folder and save cache to disk
search-notes -c index.json query specify index cache file
Writing the search index to disk will significantly speed up subsequent queries. The downside is you need to remember to update it when you files change. In the future there might be a filesystem watch mode that can do this for you.
If you want to stop using the cache, just delete the file.
% search-notes "scot* tags:stuart" -d ./test/notes
Search took 0.018347418 seconds
┌─────────┬──────────────────────┬─────────┬────────────────────────────────────────────┐
│ (index) │ File │ Score │ Hits │
├─────────┼──────────────────────┼─────────┼────────────────────────────────────────────┤
│ 0 │ 'william-wallace.md' │ '1.181' │ '"scottish" (body)' │
│ 1 │ 'prince-charlie.md' │ '0.221' │ '"scotland" (body, tags), "stuart" (tags)' │
│ 2 │ 'queen-anne.md' │ '0.189' │ '"scotland" (body), "stuart" (tags)' │
└─────────┴──────────────────────┴─────────┴────────────────────────────────────────────┘
% search-notes "scot* tags:stuart" -d ./test/notes
Search took 0.001248612 seconds
┌─────────┬──────────────────────┬─────────┬────────────────────────────────────────────┐
│ (index) │ File │ Score │ Hits │
├─────────┼──────────────────────┼─────────┼────────────────────────────────────────────┤
│ 0 │ 'william-wallace.md' │ '1.181' │ '"scottish" (body)' │
│ 1 │ 'prince-charlie.md' │ '0.221' │ '"scotland" (body, tags), "stuart" (tags)' │
│ 2 │ 'queen-anne.md' │ '0.189' │ '"scotland" (body), "stuart" (tags)' │
└─────────┴──────────────────────┴─────────┴────────────────────────────────────────────┘
You can invoke search-notes -w
with no search option to index the folder and write the index to disk.
% search-notes -d ./test/notes -w
Updated index file in 0.02012653 seconds
Search took 0.021347405 seconds
┌─────────┬──────────────────────┬─────────┬──────┐
│ (index) │ File │ Score │ Hits │
├─────────┼──────────────────────┼─────────┼──────┤
│ 0 │ 'prince-charlie.md' │ '0.000' │ '' │
│ 1 │ 'queen-anne.md' │ '0.000' │ '' │
│ 2 │ 'william-wallace.md' │ '0.000' │ '' │
└─────────┴──────────────────────┴─────────┴──────┘
"linksTo:somewhere.md linkedFrom:elsewhere.md"
)grep -n
)