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 initial index building.
_indexDict[str, Set[str]] = defaultdict(set)Inverted index mapping search tokens to sets of unique 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 to index from.

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

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 remove.

@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 string.
limitint = 20Maximum number of results to return.

Returns

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