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¶
Compare one stored field with a literal or another field.
- field: MongoField¶
- op: Literal['eq', 'ne', 'lt', 'le', 'gt', 'ge']¶
- literal: Any¶
- class httk.store.backend.mongo.searcher.IsInNode¶
Test a scalar field for explicit membership.
- field: MongoField¶
- class httk.store.backend.mongo.searcher.LinkPredicateNode¶
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¶
Match literal text in a scalar string field.
- field: MongoField¶
- mode: Literal['contains', 'startswith', 'endswith']¶
- class httk.store.backend.mongo.searcher.NotNode¶
Negate an AST node by swapping its truth and falsity filters.
- child: Any¶
- class httk.store.backend.mongo.searcher.AlwaysTrueNode¶
An AST constant that is true for every document.
- class httk.store.backend.mongo.searcher.AlwaysFalseNode¶
An AST constant that is false for every document.
- class httk.store.backend.mongo.searcher.MongoExpression(node)¶
A composable MongoDB expression backed by a neutral AST node.
- 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)¶
A scalar field, or the value channel of an embedded child field.
- is_in(*values)¶
Match a scalar member, or universally constrain a child field.
- has(value)¶
Match a child collection containing
value.
- has_any(*values)¶
Match a child collection containing any supplied value.
- has_only(*values)¶
Match a child collection containing no value outside those supplied.
- contains(text)¶
Match a literal substring, case-sensitively.
- startswith(prefix)¶
Match a literal, case-sensitive prefix.
- endswith(suffix)¶
Match a literal, case-sensitive suffix.
- class httk.store.backend.mongo.searcher.MongoLinks(variable)¶
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)¶
One weak-link traversal from a query variable to the latest live-linked targets.
Construction registers a
$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). The array is deliberately not$unwind-ed — 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)¶
Match a live linked target among
value.- Parameters:
value (Any) – The stored target to match.
- Returns:
The matching expression.
- Return type:
- has_any(*values)¶
Match at least one live linked target among
values.- Parameters:
*values (Any) – The stored targets to match.
- Returns:
The matching expression.
- Return type:
- has_only(*values)¶
Require every live linked target to be among
values(a no-links source matches).- Parameters:
*values (Any) – The complete set of allowed stored targets.
- Returns:
The condition requiring every linked target to match.
- Return type:
- class httk.store.backend.mongo.searcher.MongoLinkField(link_set, spec)¶
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.
- contains(text)¶
Match a live-linked target whose field contains
text(case-sensitive).
- startswith(prefix)¶
Match a live-linked target whose field starts with
prefix.
- endswith(suffix)¶
Match a live-linked target whose field ends with
suffix.
- class httk.store.backend.mongo.searcher.MongoVariable(searcher, cls, schema, alias)¶
A query variable, optionally produced by a lookup from another variable.
- property sid: MongoField¶
Return the store-managed sid field.
- always_true()¶
Return an expression matching every stored document.
- always_false()¶
Return an expression matching no stored document.
- property links: MongoLinks¶
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)¶
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.- offset = 0¶
- set_row_verifier(verifier, identity)¶
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.
- variable(target)¶
Bind a query variable; each additional one must be join-connected.
- output(variable, name)¶
Declare an object variable or scalar field output.
- add(expression)¶
Add a filter expression, conjoined with earlier filters.
- add_sort(field, descending=False, *, nulls='last')¶
Append a stable scalar sort with an explicit null rank.
- set_limit(limit)¶
Set the iteration limit; negative values clear it.
- add_offset(offset)¶
Add rows to the iteration offset.
- count()¶
Return the exact filtered count, ignoring offset and limit.
- results(**outputs)¶
Return a materialized
MongoResultSetfor this query.
- slicer(target)¶
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: