Skip to main content

SearchIndex

This class represents an inverted index that maps tokens to bookmark IDs. It is rebuilt from the repository upon initialization and updates incrementally as bookmarks are added or modified.

Constructor

Signature

def SearchIndex(self, repository: "BookmarkRepository") -> None: ...

Parameters

NameTypeDescription
repository"BookmarkRepository"The bookmark repository to index from.

Methods


index_bookmark()

def index_bookmark(self, bookmark: Bookmark) -> None: ...

Add or update a bookmark in the index.

Parameters

NameTypeDescription
bookmark[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)The bookmark to index.

Returns

TypeDescription
None

remove_bookmark()

def remove_bookmark(self, bookmark_id: str) -> None: ...

Remove a bookmark from the index.

Parameters

NameTypeDescription
bookmark_idstrThe unique identifier of the bookmark to remove.

Returns

TypeDescription
None

def search(self, query: str, limit: int = 20) -> List[Bookmark]: ...

Search bookmarks matching the query string. Tokens are AND-ed together — all must appear for a result to match.

Parameters

NameTypeDescription
querystrFree-text search query.
limitint = 20Maximum number of results.

Returns

TypeDescription
List[[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)]List of matching bookmarks, ordered by relevance (number of token hits).