search.dsl

Module Contents

Classes

Search

Extends elastichsearch_dsl's search object with ORM integration.

Response

Extends the default response (list of results) with additional

Hit

Extends a single result with additional methods to query the SQLAlchemy

BoundResponse

Extends the default response (list of results) with additional

Functions

type_from_hit(→ str)

explanation_value(→ dict[str, Any] | None)

Gets the value from the explanation for descriptions starting with

search.dsl.type_from_hit(hit: elasticsearch_dsl.response.Hit) str[source]
class search.dsl.Search(*args: Any, **kwargs: Any)[source]

Bases: elasticsearch_dsl.Search

Extends elastichsearch_dsl’s search object with ORM integration.

Works exactly the same as the original, but the results it returns offer additional methods to query the SQLAlchemy models behind the results (if any).

property explain: bool[source]
session: Session | None[source]
mappings: onegov.search.indexer.TypeMappingRegistry[source]
_clone() typing_extensions.Self[source]

Return a clone of the current search request. Performs a shallow copy of all the underlying objects. Used internally by most state modifying APIs.

_get_result(*args: Any, **kwargs: Any) BoundHit[source]
class search.dsl.Response(search, response, doc_class=None)[source]

Bases: elasticsearch_dsl.response.Response

Extends the default response (list of results) with additional methods to query the SQLAlchemy models behind the results.

classmethod bind(session: Session | None, mappings: TypeMappingRegistry | None, explain: bool) type[Response.bind.BoundResponse][source]
hits_by_type(type: str) Iterator[BaseHit][source]
query(type: str) Query[Any] | None[source]

Returns an SQLAlchemy query for the given type. You must provide a type, because a query can’t consist of multiple unrelated tables.

If no results match the type, None is returned.

load() list[Any][source]

Loads all results by querying the SQLAlchemy session in the order they were returned by elasticsearch.

Note that the resulting lists may include None values, since we are might get elasticsearch results for which we do not have a model on the database (the data is then out of sync).

search.dsl.explanation_value(explanation: Any, text: str) dict[str, Any] | None[source]

Gets the value from the explanation for descriptions starting with the given text.

class search.dsl.Hit(document)[source]

Bases: elasticsearch_dsl.response.Hit

Extends a single result with additional methods to query the SQLAlchemy models behind the results.

classmethod bind(model: type[onegov.search.mixins.Searchable] | None, session: Session | None) type[Hit.bind.BoundHit][source]
query() Query[Any][source]

Returns the SQLAlchemy query for this result.

load() Any[source]

Loads this result from the SQLAlchemy session.

class search.dsl.BoundResponse(search, response, doc_class=None)[source]

Bases: Response

Extends the default response (list of results) with additional methods to query the SQLAlchemy models behind the results.

session: sqlalchemy.orm.Session | None[source]
mappings: onegov.search.indexer.TypeMappingRegistry | None[source]
explain: bool[source]