Skip to main content

Qx search: OpenSearch/Elasticsearch async client, repository abstraction, index lifecycle helpers (V2 stub)

Project description

qx-search

OpenSearch/Elasticsearch async client and repository abstraction for the Qx framework.

What lives here

  • qx.search.SearchRepository[TDoc] — abstract base class for document repositories. Implement index_name and to_document / from_document mapping; the base provides index, get, delete, and search methods.
  • qx.search.SearchQuery — composable query builder: full-text query, filters, sort, pagination offset, and highlight options.
  • qx.search.SearchHit[TDoc] — single search result with the mapped document, score, and raw _source.
  • qx.search.SearchSettings — Pydantic settings for the OpenSearch/Elasticsearch endpoint URL and optional auth.
  • qx.search.create_search_client — async factory that opens an AsyncOpenSearch connection.
  • qx.search.ensure_index / drop_index — index lifecycle helpers; ensure_index creates an index with provided mapping if it doesn't exist (idempotent).

Usage

from qx.search import SearchRepository, SearchQuery, SearchSettings, create_search_client

class ProductSearchRepository(SearchRepository[ProductDoc]):
    index_name = "products"

    def to_document(self, product: Product) -> dict:
        return {"id": str(product.id), "name": product.name, "sku": product.sku}

    def from_document(self, doc: dict) -> ProductDoc:
        return ProductDoc(**doc)


# Bootstrap
client = await create_search_client(settings.search)
repo = ProductSearchRepository(client)

# Index a document
await repo.index(product)

# Search
hits = await repo.search(SearchQuery(q="widget", filters={"category": "tools"}, size=20))

Design rules

  • SearchRepository intentionally does not extend qx.db.Repository — search is a read projection, not the system of record. Write to the DB first, sync to search via an integration event handler.
  • ensure_index is safe to call at startup on every deploy; it is a no-op if the index already exists with a compatible mapping.
  • This package is a V2 scope item. The InMemorySearchRepository test double lives in qx-testing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qx_search-1.0.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qx_search-1.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file qx_search-1.0.0.tar.gz.

File metadata

  • Download URL: qx_search-1.0.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qx_search-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0d67b80ac1bbd4c97423566be3acc568314fdf8aca692c8918fd7c0b12d9b7b9
MD5 8c663e6b655b90f7b378c05d6d78f59c
BLAKE2b-256 5fff898604390d9bf21923396e96d4d2d6e89aae81906c53d6cc198d85cfdf16

See more details on using hashes here.

File details

Details for the file qx_search-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: qx_search-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qx_search-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41ad2924957378b7acbb22b4297a735c3383b9a72afa999c64742c2e02026f86
MD5 3408f1b80c76cf54541caa44ee0b0008
BLAKE2b-256 3ac87a453985395884efa83518823cfca620de82bbfa9c09a694d439500a94a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page