Skip to main content

SearchIndex

Inverted index mapping tokens to bookmark IDs. Rebuilt from the repository on initialisation and updated incrementally when bookmarks are added or modified.

Attributes

AttributeTypeDescription
_repo[BookmarkRepository](../../../db/repository/bookmarkrepository.md?sid=app_db_repository_bookmarkrepository)The bookmark repository to index from.
_indexDict[str, Set[str]]Inverted index mapping tokens to bookmark IDs.

Constructor

Signature

def SearchIndex(
repository: [BookmarkRepository](../../../db/repository/bookmarkrepository.md?sid=app_db_repository_bookmarkrepository)
) - > None

Parameters

NameTypeDescription
repository[BookmarkRepository](../../../db/repository/bookmarkrepository.md?sid=app_db_repository_bookmarkrepository)The bookmark repository to index from.

Methods


index_bookmark()

@classmethod
def index_bookmark(
bookmark: [Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)
) - > None

Add or update a bookmark in the index. This method removes any existing entries for the bookmark and then tokenizes its title and description to create new index entries.

Parameters

NameTypeDescription
bookmark[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)The bookmark object to be added or updated in the index.

Returns

TypeDescription
NoneNone

remove_bookmark()

@classmethod
def remove_bookmark(
bookmark_id: str
) - > None

Remove a bookmark from the index using its unique identifier. This operation cleans up all associated token entries for the specified bookmark.

Parameters

NameTypeDescription
bookmark_idstrThe unique identifier of the bookmark to remove from the index.

Returns

TypeDescription
NoneNone

@classmethod
def search(
query: str,
limit: int = 20
) - > List[[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)]

Search bookmarks matching the query string. Results are AND-ed together and returned in order of relevance, limited by the specified count.

Parameters

NameTypeDescription
querystrThe free-text search query used to find matching bookmarks.
limitint = 20The maximum number of search results to return.

Returns

TypeDescription
List[[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)]A list of matching Bookmark objects, ordered by relevance.