Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion test/collection/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@
_FilterValue,
_Operator,
)
from weaviate.collections.filters import _FilterToGRPC
from weaviate.collections.filters import _FilterToGRPC, _FilterToREST
from weaviate.proto.v1 import base_pb2


@pytest.mark.parametrize("compound", [False, True])
def test_graphql_reference_count_filter(compound: bool) -> None:
"""Serialize reference-count targets for direct and compound GraphQL filters."""
ref_filter = wvc.query.Filter.by_ref_count("ref").greater_than(0)
expected_ref = {
"operator": "GreaterThan",
"path": ["ref"],
"valueInt": 0,
}
if compound:
combined = ref_filter & wvc.query.Filter.by_property("name").equal("Berlin")
assert _FilterToREST.convert(combined) == {
"operator": "And",
"operands": [
expected_ref,
{"operator": "Equal", "path": ["name"], "valueText": "Berlin"},
],
}
else:
assert _FilterToREST.convert(ref_filter) == expected_ref


def test_empty_input_contains_any() -> None:
with pytest.raises(weaviate.exceptions.WeaviateInvalidInputError):
wvc.query.Filter.by_id().contains_any([])
Expand Down
2 changes: 2 additions & 0 deletions weaviate/collections/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ def __value_filter(weav_filter: _FilterValue) -> Dict[str, Any]:
def __to_path(target: _FilterTargets) -> List[str]:
if isinstance(target, str):
return [target]
elif isinstance(target, _CountRef):
return [target.link_on]
elif isinstance(target, _SingleTargetRef):
raise WeaviateInvalidInputError(
"Cannot use Filter.by_ref() in the aggregate API currently. Instead use Filter.by_ref_multi_target() and specify the target collection explicitly."
Expand Down
Loading