vault

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = fmt.Errorf("operation not supported by obsidian backend")

ErrNotSupported is returned for Logseq-specific operations (DataScript queries).

View Source
var ErrPathEscape = fmt.Errorf("path escapes vault boundary")

ErrPathEscape is returned when a resolved path escapes the vault boundary.

Functions

func SortByRelevance added in v0.4.0

func SortByRelevance(results []SearchResult, query string)

SortByRelevance sorts search results by term frequency. Not currently used but available for future ranking improvements.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements backend.Backend for an Obsidian vault on disk. It reads all .md files on initialization and serves queries from memory.

func New

func New(vaultPath string, opts ...Option) *Client

New creates a new Obsidian vault client. Call Load() to index the vault.

func (*Client) AppendBlockInPage

func (c *Client) AppendBlockInPage(_ context.Context, page string, content string) (*types.BlockEntity, error)
func (c *Client) BuildBacklinks()

BuildBacklinks must be called after Load() to build the reverse link index.

func (*Client) Close added in v0.4.0

func (c *Client) Close() error

Close stops the file watcher and any pending debounce timers. Without this, timers scheduled before shutdown would still fire and mutate c.pages / log spam after the server has stopped.

func (*Client) CreatePage

func (c *Client) CreatePage(_ context.Context, name string, properties map[string]any, opts map[string]any) (*types.PageEntity, error)

func (*Client) DatascriptQuery

func (c *Client) DatascriptQuery(_ context.Context, query string, inputs ...any) (json.RawMessage, error)

func (*Client) DeletePage added in v0.4.0

func (c *Client) DeletePage(_ context.Context, name string) error

func (*Client) FindBlocksByTag

func (c *Client) FindBlocksByTag(_ context.Context, tag string, includeChildren bool) ([]backend.TagResult, error)

FindBlocksByTag scans all pages for blocks containing the given #tag. Implements backend.TagSearcher.

func (*Client) FindByProperty

func (c *Client) FindByProperty(_ context.Context, key, value, operator string) ([]backend.PropertyResult, error)

FindByProperty scans all pages for matching frontmatter properties. Implements backend.PropertySearcher.

func (*Client) FullTextSearch added in v0.4.0

func (c *Client) FullTextSearch(_ context.Context, query string, limit int) ([]backend.SearchHit, error)

FullTextSearch uses the inverted index for efficient full-text search. Implements backend.FullTextSearcher.

func (*Client) GetAllPages

func (c *Client) GetAllPages(_ context.Context) ([]types.PageEntity, error)

func (*Client) GetBlock

func (c *Client) GetBlock(_ context.Context, uuid string, opts ...map[string]any) (*types.BlockEntity, error)

func (*Client) GetPage

func (c *Client) GetPage(_ context.Context, nameOrID any) (*types.PageEntity, error)

func (*Client) GetPageBlocksTree

func (c *Client) GetPageBlocksTree(_ context.Context, nameOrID any) ([]types.BlockEntity, error)

func (*Client) GetPageLinkedReferences

func (c *Client) GetPageLinkedReferences(_ context.Context, nameOrID any) (json.RawMessage, error)

func (*Client) InsertBlock

func (c *Client) InsertBlock(_ context.Context, srcBlock any, content string, opts map[string]any) (*types.BlockEntity, error)

func (*Client) Load

func (c *Client) Load() error

Load reads all .md files in the vault and builds the in-memory index.

func (*Client) MoveBlock

func (c *Client) MoveBlock(_ context.Context, uuid string, targetUUID string, opts map[string]any) error

func (*Client) Ping

func (c *Client) Ping(_ context.Context) error

func (*Client) PrependBlockInPage

func (c *Client) PrependBlockInPage(_ context.Context, page string, content string) (*types.BlockEntity, error)

func (*Client) Reload added in v0.4.0

func (c *Client) Reload() error

Reload forces a full vault re-index.

func (*Client) RemoveBlock

func (c *Client) RemoveBlock(_ context.Context, uuid string) error

func (*Client) RenamePage added in v0.4.0

func (c *Client) RenamePage(_ context.Context, oldName, newName string) error

func (*Client) SearchJournals

func (c *Client) SearchJournals(_ context.Context, query, from, to string) ([]backend.JournalResult, error)

SearchJournals scans daily notes for matching content. Implements backend.JournalSearcher.

func (*Client) UpdateBlock

func (c *Client) UpdateBlock(_ context.Context, uuid string, content string, opts ...map[string]any) error

func (*Client) Watch added in v0.4.0

func (c *Client) Watch() error

Watch starts watching the vault directory for file changes and automatically re-indexes modified files. Runs in a goroutine and logs errors to stderr.

type Option

type Option func(*Client)

Option configures a vault Client.

func WithDailyFolder

func WithDailyFolder(folder string) Option

WithDailyFolder sets the daily notes subfolder (default: "daily notes").

func WithIncludeHidden added in v0.5.0

func WithIncludeHidden(include bool) Option

WithIncludeHidden controls whether directories starting with "." are indexed. By default hidden directories are skipped. When set to true, hidden directories are included (except .git, which is always skipped). This is useful for projects that store configuration or documentation in directories like .specify/ or .opencode/.

type SearchIndex added in v0.4.0

type SearchIndex struct {
	// contains filtered or unexported fields
}

SearchIndex is a simple inverted index for full-text search. Maps lowercase terms to the blocks containing them.

func NewSearchIndex added in v0.4.0

func NewSearchIndex() *SearchIndex

NewSearchIndex creates an empty search index.

func (*SearchIndex) BuildFrom added in v0.4.0

func (si *SearchIndex) BuildFrom(pages map[string]*cachedPage)

BuildFrom indexes all pages in the vault.

func (*SearchIndex) ReindexPage added in v0.4.0

func (si *SearchIndex) ReindexPage(page *cachedPage)

ReindexPage removes and re-adds a single page to the index.

func (*SearchIndex) RemovePage added in v0.4.0

func (si *SearchIndex) RemovePage(lowerName string)

RemovePage removes a page from the index.

func (*SearchIndex) Search added in v0.4.0

func (si *SearchIndex) Search(query string, limit int) []SearchResult

Search finds blocks matching all terms in the query (AND semantics). Returns results sorted by relevance (number of term hits).

type SearchResult added in v0.4.0

type SearchResult struct {
	PageName string `json:"page"`
	UUID     string `json:"uuid"`
	Content  string `json:"content"`
}

SearchResult is a block that matched a search query.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL