Skip to content

Commit c307799

Browse files
committed
doc edits
1 parent 0dc6ace commit c307799

File tree

4 files changed

+197
-292
lines changed

4 files changed

+197
-292
lines changed

django_mongodb_backend/compiler.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, *args, **kwargs):
3434
# A list of OrderBy objects for this query.
3535
self.order_by_objs = None
3636
self.subqueries = []
37-
# Atlas search calls
37+
# Atlas search stage.
3838
self.search_pipeline = []
3939

4040
def _get_group_alias_column(self, expr, annotation_group_idx):
@@ -65,8 +65,8 @@ def _get_replace_expr(self, sub_expr, group, alias):
6565
column_target.set_attributes_from_name(alias)
6666
inner_column = Col(self.collection_name, column_target)
6767
if getattr(sub_expr, "distinct", False):
68-
# If the expression should return distinct values, use
69-
# $addToSet to deduplicate.
68+
# If the expression should return distinct values, use $addToSet to
69+
# deduplicate.
7070
rhs = sub_expr.as_mql(self, self.connection, resolve_inner_expression=True)
7171
group[alias] = {"$addToSet": rhs}
7272
replacing_expr = sub_expr.copy()
@@ -112,9 +112,10 @@ def _prepare_search_expressions_for_pipeline(self, expression, search_idx, repla
112112
"""
113113
Collect and prepare unique search expressions for inclusion in an
114114
aggregation pipeline.
115-
Iterates over all search sub-expressions of the given expression,
116-
assigns a unique alias to each, and maps them to their
117-
replacement expressions.
115+
116+
Iterate over all search sub-expressions of the given expression.
117+
Assigning a unique alias to each and map them to their replacement
118+
expressions.
118119
"""
119120
searches = {}
120121
for sub_expr in self._get_search_expressions(expression):
@@ -126,23 +127,21 @@ def _prepare_search_query_for_aggregation_pipeline(self, order_by):
126127
"""
127128
Prepare expressions for the search pipeline.
128129
129-
Handle the computation of search functions used by various
130-
expressions. Separate and create intermediate columns, and replace
131-
nodes to simulate a search operation.
130+
Handle the computation of search functions used by various expressions.
131+
Separate and create intermediate columns, and replace nodes to simulate
132+
a search operation.
132133
133-
MongoDB's $search or $searchVector are stages. To apply operations over them,
134-
compute the $search or $vectorSearch first, then apply additional operations in a subsequent
135-
stage by replacing the aggregate expressions with new document field prefixed
136-
by `__search_expr.search#`.
134+
To apply operations over the $search or $searchVector stages, compute
135+
the $search or $vectorSearch first, then apply additional operations in
136+
a subsequent stage by replacing the aggregate expressions with a new
137+
document field prefixed by `__search_expr.search#`.
137138
"""
138139
replacements = {}
139140
annotation_group_idx = itertools.count(start=1)
140141
for expr in self.query.annotation_select.values():
141142
self._prepare_search_expressions_for_pipeline(expr, annotation_group_idx, replacements)
142-
143143
for expr, _ in order_by:
144144
self._prepare_search_expressions_for_pipeline(expr, annotation_group_idx, replacements)
145-
146145
self._prepare_search_expressions_for_pipeline(
147146
self.having, annotation_group_idx, replacements
148147
)
@@ -257,13 +256,14 @@ def _build_aggregation_pipeline(self, ids, group):
257256

258257
def _compound_searches_queries(self, search_replacements):
259258
"""
260-
Builds a query pipeline from a mapping of search expressions to result columns.
259+
Build a query pipeline from a mapping of search expressions to result
260+
columns.
261261
262-
Currently, only a single `$search` or `$vectorSearch` expression is supported.
263-
Combining multiple search expressions is not yet allowed and will raise a ValueError.
262+
Currently only a single $search or $vectorSearch expression is
263+
supported. Combining multiple search expressions raises ValueError.
264264
265-
This method will eventually support hybrid search by allowing the combination of
266-
`$search` and `$vectorSearch` operations.
265+
This method will eventually support hybrid search by allowing the
266+
combination of $search and $vectorSearch operations.
267267
"""
268268
if not search_replacements:
269269
return []

0 commit comments

Comments
 (0)