Skip to content

Commit 7639596

Browse files
authored
fix: support cases when there is both field condition and logical operators (#1076)
1 parent ee771e7 commit 7639596

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

src/memos/vec_dbs/milvus.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,33 @@ def _dict_to_expr(self, filter_dict: dict[str, Any]) -> str:
287287
def _build_expression(self, condition: Any) -> str:
288288
"""Build expression from condition dict or value."""
289289
if isinstance(condition, dict):
290+
conditions = []
291+
290292
# Handle logical operators
291293
if "and" in condition:
292-
return self._handle_logical_and(condition["and"])
293-
elif "or" in condition:
294-
return self._handle_logical_or(condition["or"])
295-
elif "not" in condition:
296-
return self._handle_logical_not(condition["not"])
297-
else:
298-
# Handle field conditions
299-
return self._handle_field_conditions(condition)
294+
and_expr = self._handle_logical_and(condition["and"])
295+
if and_expr:
296+
conditions.append(and_expr)
297+
if "or" in condition:
298+
or_expr = self._handle_logical_or(condition["or"])
299+
if or_expr:
300+
conditions.append(or_expr)
301+
if "not" in condition:
302+
not_expr = self._handle_logical_not(condition["not"])
303+
if not_expr:
304+
conditions.append(not_expr)
305+
306+
# Handle field conditions (keys that are not logical operators)
307+
field_dict = {k: v for k, v in condition.items() if k not in ["and", "or", "not"]}
308+
if field_dict:
309+
field_expr = self._handle_field_conditions(field_dict)
310+
if field_expr:
311+
conditions.append(field_expr)
312+
313+
# Combine all conditions with AND
314+
if not conditions:
315+
return ""
316+
return " and ".join(conditions)
300317
else:
301318
# Simple value comparison
302319
return f"{condition}"

0 commit comments

Comments
 (0)