Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scientific Metadata Search Engine client service using TypeSense #697

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add typesense dependency
  • Loading branch information
Kezzsim committed Mar 6, 2024
commit 0af60a8943fb419a47d02bffe81278a9b0fc50bc
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ all = [
"xarray",
"zarr",
"zstandard",
"typesense",
]
# These are needed by the client and server to transmit/receive arrays.
array = [
Expand Down
11 changes: 11 additions & 0 deletions tiled/catalog/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from urllib.parse import quote_plus, urlparse

import anyio
import typesense
from fastapi import HTTPException
from sqlalchemy import delete, event, func, not_, or_, select, text, type_coerce, update
from sqlalchemy.dialects.postgresql import JSONB, REGCONFIG
Expand Down Expand Up @@ -1167,6 +1168,7 @@ def in_memory(
readable_storage=None,
echo=DEFAULT_ECHO,
adapters_by_mimetype=None,
typesenseClient=None,
):
uri = "sqlite+aiosqlite:///:memory:"
return from_uri(
Expand All @@ -1178,6 +1180,7 @@ def in_memory(
readable_storage=readable_storage,
echo=echo,
adapters_by_mimetype=adapters_by_mimetype,
typesenseClient=typesenseClient,
)


Expand All @@ -1192,6 +1195,7 @@ def from_uri(
init_if_not_exists=False,
echo=DEFAULT_ECHO,
adapters_by_mimetype=None,
typesenseClient=None,
):
uri = str(uri)
if init_if_not_exists:
Expand All @@ -1213,6 +1217,13 @@ def from_uri(
engine = create_async_engine(uri, echo=echo, json_serializer=json_serializer)
if engine.dialect.name == "sqlite":
event.listens_for(engine.sync_engine, "connect")(_set_sqlite_pragma)
if typesenseClient:
typesenseClient = typesense.client(
typesenseClient["host"],
typesenseClient["port"],
typesenseClient["protocol"],
typesenseClient["api_key"],
)
return CatalogContainerAdapter(
Context(engine, writable_storage, readable_storage, adapters_by_mimetype),
RootNode(metadata, specs, access_policy),
Expand Down