Skip to main content

SearchIndex

Inverted index mapping tokens to bookmark IDs.

Attributes

AttributeTypeDescription
_repo[BookmarkRepository](../../../db/repository/bookmarkrepository.md?sid=app_db_repository_bookmarkrepository)The bookmark repository used to fetch bookmark details and rebuild the index.
_indexDict[str, Set[str]]Inverted index mapping tokens to sets of bookmark IDs for efficient search retrieval.

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 instance to be indexed.

Methods


index_bookmark()

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

Add or update a bookmark in the index.

Parameters

NameTypeDescription
bookmark[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)The bookmark object containing the title and description to be indexed.

remove_bookmark()

@classmethod
def remove_bookmark(
bookmark_id: str
)

Remove a bookmark from the index.

Parameters

NameTypeDescription
bookmark_idstrThe unique identifier of the bookmark to be removed from the search index.

@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. Tokens are AND-ed together — all must appear for a result to match.

Parameters

NameTypeDescription
querystrFree-text search query containing the terms to match against indexed bookmarks.
limitint = 20Maximum number of results to return from the search.

Returns

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