mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-14 15:14:31 -04:00
20 lines
No EOL
774 B
Python
20 lines
No EOL
774 B
Python
from typing import List
|
|
|
|
from sonic import IngestClient, SearchClient
|
|
|
|
from archivebox.util import enforce_types
|
|
from archivebox.config import SEARCH_BACKEND_HOST_NAME, SEARCH_BACKEND_PORT, SEARCH_BACKEND_PASSWORD, SONIC_BUCKET, SONIC_COLLECTION
|
|
|
|
|
|
@enforce_types
|
|
def index(snapshot_id: str, texts: List[str]):
|
|
with IngestClient(SEARCH_BACKEND_HOST_NAME, SEARCH_BACKEND_PORT, SEARCH_BACKEND_PASSWORD) as ingestcl:
|
|
for text in texts:
|
|
ingestcl.push(SONIC_BUCKET, SONIC_COLLECTION, snapshot_id, str(text))
|
|
|
|
@enforce_types
|
|
def search(text: str) -> List:
|
|
with SearchClient(SEARCH_BACKEND_HOST_NAME, SEARCH_BACKEND_PORT, SEARCH_BACKEND_PASSWORD) as querycl:
|
|
snap_ids = querycl.query(SONIC_BUCKET, SONIC_COLLECTION, text)
|
|
return snap_ids
|
|
|