httk.store.backend.mongo.searcher¶
MongoDB query planning for the neutral httk.store.query protocols.
The planner keeps a truth/falsity pair for each predicate. This is important
for embedded arrays: the negation of “some element matches” is “no element
matches”, not MongoDB’s row-like $ne interpretation.
Classes¶
Compare one stored field with a literal or another field. |
|
Test a scalar field for explicit membership. |
|
A no- |
|
Match literal text in a scalar string field. |
|
Conjoin two AST nodes. |
|
Disjoin two AST nodes. |
|
Negate an AST node by swapping its truth and falsity filters. |
|
An AST constant that is true for every document. |
|
An AST constant that is false for every document. |
|
A composable MongoDB expression backed by a neutral AST node. |
|
A scalar field, or the value channel of an embedded child field. |
|
The |
|
One weak-link traversal from a query variable to the latest live-linked targets. |
|
A scalar or encoded field of a weak-link target, compared existentially. |
|
A query variable, optionally produced by a lookup from another variable. |
|
Build and execute a MongoDB query over reference-connected variables. |
Module Contents¶
- class httk.store.backend.mongo.searcher.ComparisonNode[source]¶
Compare one stored field with a literal or another field.
- field: MongoField[source]¶
- class httk.store.backend.mongo.searcher.IsInNode[source]¶
Test a scalar field for explicit membership.
- field: MongoField[source]¶
- class httk.store.backend.mongo.searcher.LinkPredicateNode[source]¶
A no-
$unwindexistential/universal predicate over a weak-link target array.The link
$lookupleaves each source document carrying an array field atpathof its live, latest-of-lineage link elements (each withtarget_lidand an embedded_httk_targetdoc).predicateis an$elemMatchbody matching one such element. For an existential (universal=False:==/has_any/ a chained-field comparison) the truth is “some element matches” and the falsity “no element matches” — the latter vacuously true for a zero-link source, so~negates set-wise. For a universal (universal=True:has_only)predicatematches an outsider: truth is “no outsider”, falsity “some outsider”.
- class httk.store.backend.mongo.searcher.StringMatchNode[source]¶
Match literal text in a scalar string field.
- field: MongoField[source]¶
- class httk.store.backend.mongo.searcher.NotNode[source]¶
Negate an AST node by swapping its truth and falsity filters.
- class httk.store.backend.mongo.searcher.AlwaysTrueNode[source]¶
An AST constant that is true for every document.
- class httk.store.backend.mongo.searcher.AlwaysFalseNode[source]¶
An AST constant that is false for every document.
- class httk.store.backend.mongo.searcher.MongoExpression(node)[source]¶
A composable MongoDB expression backed by a neutral AST node.
- class httk.store.backend.mongo.searcher.MongoField(variable, key_path, spec, codec=None, child_keys=(), presentation_prefix='', operand_converter=None, presentation_converter=None, alternative_composite=False)[source]¶
A scalar field, or the value channel of an embedded child field.
- class httk.store.backend.mongo.searcher.MongoLinks(variable)[source]¶
The
linksnamespace of a query variable: one weak link per attribute.Each attribute access resolves the declared
LinkSpecand returns a freshMongoLinkSet— a new link$lookuparray every time, never memoized on(variable, name). That freshness lets AND-composed predicates on the same link constrain independent link elements (so(v.links.p.name == 'A') & (v.links.p.name == 'B')is a HAS-ALL over two distinct linked targets), matching the SQL backend and OPTIMADE HAS ALL.- Parameters:
variable (MongoVariable) – The query variable whose weak links this namespace exposes.
- class httk.store.backend.mongo.searcher.MongoLinkSet(variable, spec)[source]¶
One weak-link traversal from a query variable to the latest live-linked targets.
Construction registers nothing: the
$lookupthat leaves each source document carrying an array field (_httk_link_<n>) of its live, latest-of-lineage link elements, each embedding the latest revision of its target lineage as_httk_target(bounded byas_ofwhen set), is appended lazily by_register()on first use as a predicate operand — so a link set used only as a set-valuedresults()output (resolved after the query, from the parent document’s ownlogical_id) never adds a$lookupstage. The array is deliberately not$unwind-ed once registered — that would multiply source documents and break grouped multiplicity and count(); predicates are no-unwind$elemMatcharray predicates instead (seeLinkPredicateNode).Identity comparisons (
== stored_object,has_any(),has_only()) run over each element’starget_lid; attribute access chains into a scalar or encoded field of the latest target revision.- Parameters:
variable (MongoVariable) – The query variable the link traverses from.
spec (httk.store.backend.schema.LinkSpec) – The resolved weak-link declaration.
- has(value)[source]¶
Match a live linked target among
value.- Parameters:
value (Any) – The stored target to match.
- Returns:
The matching expression.
- Return type:
- has_any(*values)[source]¶
Match at least one live linked target among
values.- Parameters:
*values (Any) – The stored targets to match.
- Returns:
The matching expression.
- Return type:
- class httk.store.backend.mongo.searcher.MongoLinkField(link_set, spec)[source]¶
A scalar or encoded field of a weak-link target, compared existentially.
Each comparison yields a
LinkPredicateNodewhose$elemMatchbody reaches into the embedded_httk_targetdoc of a link element: the match is “some live-linked target satisfies the comparison”, and~negates set-wise (including a vacuous match on a zero-link source).- Parameters:
link_set (MongoLinkSet) – The traversal supplying the link array path and target codec context.
spec (httk.store.backend.schema.FieldSpec) – The resolved scalar or encoded target field.
- class httk.store.backend.mongo.searcher.MongoVariable(searcher, cls, schema, alias)[source]¶
A query variable, optionally produced by a lookup from another variable.
- property sid: MongoField[source]¶
Return the store-managed sid field.
- property links: MongoLinks[source]¶
Return the weak-link namespace of this variable.
- class httk.store.backend.mongo.searcher.MongoSearcher(store, *, as_of=None, only_latest=False, only_main_alt=True)[source]¶
Build and execute a MongoDB query over reference-connected variables.
An historic cutoff is injected for every root and lookup variable; visible rows’ dependencies are always visible because references only point at earlier-or-equal rows from the same transaction. When
only_latestis set, every declared (root) variable is additionally restricted to the latest document of itslogical_idlineage by sid (bounded byas_ofwhen given); reference/lookup variables stay unfiltered so pinned references may still resolve replaced documents.- set_row_verifier(verifier, identity)[source]¶
Attach the client-authoritative candidate verifier and its frozen identity.
The identity must be the canonical logical predicate payload, including every verifier constant. It is folded into continuation fingerprints, so cursors never cross between otherwise identical server plans.
- output(variable, name)[source]¶
Declare an object variable, scalar field, or weak-link-set output.
A weak-link-set output (a bare
v.links.<name>) yields a tuple of the latest live-linked targets per row, resolved after the query from the source document’s ownlogical_id; it registers no$lookup, unlike predicate use of the same link set. Chaining into a target field (v.links.<name>.<field>) stays rejected.
- add_sort(field, descending=False, *, nulls='last')[source]¶
Append a stable scalar sort with an explicit null rank.
- results(**outputs)[source]¶
Return a materialized
MongoResultSetfor this query.
- slicer(target)[source]¶
A pandas-style
[]indexing view overtargetrecords.Each terminal indexing operation runs against a fresh searcher minted with this searcher’s
as_of/only_latest/only_main_altscope, so slicer operations never share filter state.- Parameters:
target (type) – The stored record class to index.
- Returns:
A slicer over
target.- Return type: