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 retrieve full bookmark objects during search and index rebuilding.
_indexDict[str, Set[str]]An inverted index mapping search tokens to sets of bookmark IDs for efficient lookup.

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.

Signature

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

Parameters

NameTypeDescription
repository[BookmarkRepository](../../../db/repository/bookmarkrepository.md?sid=app_db_repository_bookmarkrepository)The bookmark repository instance used to fetch data for indexing.

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 tokenized and 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 purged 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 used to filter 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).