SearchIndex
Inverted index mapping tokens to bookmark IDs. Rebuilt from the repository on initialisation and updated incrementally when bookmarks are added or modified.
Attributes
| Attribute | Type | Description |
|---|---|---|
| _repo | [BookmarkRepository](../../../db/repository/bookmarkrepository.md?sid=app_db_repository_bookmarkrepository) | The bookmark repository to index from. |
| _index | Dict[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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| bookmark | [Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark) | The bookmark object to be added or updated in the index. |
Returns
| Type | Description |
|---|---|
None | None |
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
| Name | Type | Description |
|---|---|---|
| bookmark_id | str | The unique identifier of the bookmark to remove from the index. |
Returns
| Type | Description |
|---|---|
None | None |
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. Results are AND-ed together and returned in order of relevance, limited by the specified count.
Parameters
| Name | Type | Description |
|---|---|---|
| query | str | The free-text search query used to find matching bookmarks. |
| limit | int = 20 | The maximum number of search results to return. |
Returns
| Type | Description |
|---|---|
List[[Bookmark](../../../models/bookmark/bookmark.md?sid=app_models_bookmark_bookmark)] | A list of matching Bookmark objects, ordered by relevance. |