SearchIndex
Inverted index mapping tokens to bookmark IDs.
Attributes
| Attribute | Type | Description |
|---|---|---|
| _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. |
| _index | Dict[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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| bookmark_id | str | The unique identifier of the bookmark to be purged from the search index. |
search()
@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
| Name | Type | Description |
|---|---|---|
| query | str | Free-text search query used to filter bookmarks. |
| limit | int = 20 | Maximum number of results to return from the search. |
Returns
| Type | Description |
|---|---|
List[[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)] | List of matching bookmarks, ordered by relevance (number of token hits). |