httk.store.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

ComparisonNode

Compare one stored field with a literal or another field.

IsInNode

Test a scalar field for explicit membership.

StringMatchNode

Match literal text in a scalar string field.

AndNode

Conjoin two AST nodes.

OrNode

Disjoin two AST nodes.

NotNode

Negate an AST node by swapping its truth and falsity filters.

AlwaysTrueNode

An AST constant that is true for every document.

AlwaysFalseNode

An AST constant that is false for every document.

MongoExpression

A composable MongoDB expression backed by a neutral AST node.

MongoField

A scalar field, or the value channel of an embedded child field.

MongoVariable

A query variable, optionally produced by a lookup from another variable.

MongoSearcher

Build and execute a MongoDB query over reference-connected variables.

Module Contents

class httk.store.mongo.searcher.ComparisonNode[source]

Compare one stored field with a literal or another field.

field: MongoField[source]
op: Literal['eq', 'ne', 'lt', 'le', 'gt', 'ge'][source]
literal: Any[source]
class httk.store.mongo.searcher.IsInNode[source]

Test a scalar field for explicit membership.

field: MongoField[source]
values: tuple[Any, Ellipsis][source]
class httk.store.mongo.searcher.StringMatchNode[source]

Match literal text in a scalar string field.

field: MongoField[source]
mode: Literal['contains', 'startswith', 'endswith'][source]
text: str[source]
class httk.store.mongo.searcher.AndNode[source]

Conjoin two AST nodes.

left: Any[source]
right: Any[source]
class httk.store.mongo.searcher.OrNode[source]

Disjoin two AST nodes.

left: Any[source]
right: Any[source]
class httk.store.mongo.searcher.NotNode[source]

Negate an AST node by swapping its truth and falsity filters.

child: Any[source]
class httk.store.mongo.searcher.AlwaysTrueNode[source]

An AST constant that is true for every document.

class httk.store.mongo.searcher.AlwaysFalseNode[source]

An AST constant that is false for every document.

class httk.store.mongo.searcher.MongoExpression(node)[source]

A composable MongoDB expression backed by a neutral AST node.

node[source]
class httk.store.mongo.searcher.MongoField(variable, key_path, spec, codec=None, child_keys=(), presentation_prefix='')[source]

A scalar field, or the value channel of an embedded child field.

is_in(*values)[source]

Match a scalar member, or universally constrain a child field.

has(value)[source]

Match a child collection containing value.

has_any(*values)[source]

Match a child collection containing any supplied value.

has_only(*values)[source]

Match a child collection containing no value outside those supplied.

contains(text)[source]

Match a literal substring, case-sensitively.

startswith(prefix)[source]

Match a literal, case-sensitive prefix.

endswith(suffix)[source]

Match a literal, case-sensitive suffix.

class httk.store.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.

always_true()[source]

Return an expression matching every stored document.

always_false()[source]

Return an expression matching no stored document.

class httk.store.mongo.searcher.MongoSearcher(store)[source]

Build and execute a MongoDB query over reference-connected variables.

offset = 0[source]
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.

Parameters:
Raises:

TypeError – If either attachment component has the wrong type.

variable(target)[source]

Bind a query variable; each additional one must be join-connected.

output(variable, name)[source]

Declare an object variable or scalar field output.

add(expression)[source]

Add a filter expression, conjoined with earlier filters.

add_sort(field, descending=False, *, nulls='last')[source]

Append a stable scalar sort with an explicit null rank.

set_limit(limit)[source]

Set the iteration limit; negative values clear it.

add_offset(offset)[source]

Add rows to the iteration offset.

count()[source]

Return the exact filtered count, ignoring offset and limit.

results(**outputs)[source]

Return a materialized MongoResultSet for this query.