@@ -1028,16 +1028,16 @@ def test_count_unique_metadata_by_filter_all_documents(document_store: DocumentS
10281028 counts = document_store .count_unique_metadata_by_filter ( # type:ignore[attr-defined]
10291029 filters = {}, metadata_fields = ["category" , "status" , "priority" ]
10301030 )
1031- assert counts ["category" ] == 3
1032- assert counts ["status" ] == 2
1033- assert counts ["priority" ] == 3
1031+ assert counts == {"category" : 3 , "status" : 2 , "priority" : 3 }
10341032
10351033 @staticmethod
10361034 def test_count_unique_metadata_by_filter_with_filter (document_store : DocumentStore ):
10371035 """Test count_unique_metadata_by_filter() with a filter."""
1036+ # The filtered-out document carries extra unique values, so the counts only come out right
1037+ # when the store actually applies the filter.
10381038 docs = [
10391039 Document (content = "Doc 1" , meta = {"category" : "A" , "status" : "active" , "priority" : 1 }),
1040- Document (content = "Doc 2" , meta = {"category" : "B" , "status" : "active " , "priority" : 2 }),
1040+ Document (content = "Doc 2" , meta = {"category" : "B" , "status" : "archived " , "priority" : 2 }),
10411041 Document (content = "Doc 3" , meta = {"category" : "A" , "status" : "inactive" , "priority" : 1 }),
10421042 Document (content = "Doc 4" , meta = {"category" : "A" , "status" : "active" , "priority" : 3 }),
10431043 ]
@@ -1047,8 +1047,7 @@ def test_count_unique_metadata_by_filter_with_filter(document_store: DocumentSto
10471047 counts = document_store .count_unique_metadata_by_filter ( # type:ignore[attr-defined]
10481048 filters = {"field" : "meta.category" , "operator" : "==" , "value" : "A" }, metadata_fields = ["status" , "priority" ]
10491049 )
1050- assert counts ["status" ] == 2
1051- assert counts ["priority" ] == 2
1050+ assert counts == {"status" : 2 , "priority" : 2 }
10521051
10531052 @staticmethod
10541053 def test_count_unique_metadata_by_filter_with_multiple_filters (document_store : DocumentStore ):
@@ -1121,11 +1120,14 @@ class GetMetadataFieldMinMaxTest:
11211120 @staticmethod
11221121 def test_get_metadata_field_min_max_numeric (document_store : DocumentStore ):
11231122 """Test get_metadata_field_min_max() with integer field."""
1123+ # The min and max are deliberately not the first or last written values, so an implementation
1124+ # returning values by insertion order fails. Keeping both 10 and 5 catches implementations that
1125+ # compare numbers as strings ("10" < "5" lexicographically).
11241126 docs = [
1125- Document (content = "Doc 1" , meta = {"priority" : 1 }),
1126- Document (content = "Doc 2" , meta = {"priority" : 5 }),
1127- Document (content = "Doc 3" , meta = {"priority" : 3 }),
1128- Document (content = "Doc 4" , meta = {"priority" : 10 }),
1127+ Document (content = "Doc 1" , meta = {"priority" : 5 }),
1128+ Document (content = "Doc 2" , meta = {"priority" : 1 }),
1129+ Document (content = "Doc 3" , meta = {"priority" : 10 }),
1130+ Document (content = "Doc 4" , meta = {"priority" : 3 }),
11291131 ]
11301132 document_store .write_documents (docs )
11311133 assert document_store .count_documents () == 4
@@ -1137,13 +1139,15 @@ def test_get_metadata_field_min_max_numeric(document_store: DocumentStore):
11371139 @staticmethod
11381140 def test_get_metadata_field_min_max_float (document_store : DocumentStore ):
11391141 """Test get_metadata_field_min_max() with float field."""
1142+ # The min and max are deliberately not the first or last written values.
11401143 docs = [
1141- Document (content = "Doc 1" , meta = {"rating" : 0.6 }),
1142- Document (content = "Doc 2" , meta = {"rating" : 0.95 }),
1143- Document (content = "Doc 3" , meta = {"rating" : 0.8 }),
1144+ Document (content = "Doc 1" , meta = {"rating" : 0.8 }),
1145+ Document (content = "Doc 2" , meta = {"rating" : 0.6 }),
1146+ Document (content = "Doc 3" , meta = {"rating" : 0.95 }),
1147+ Document (content = "Doc 4" , meta = {"rating" : 0.7 }),
11441148 ]
11451149 document_store .write_documents (docs )
1146- assert document_store .count_documents () == 3
1150+ assert document_store .count_documents () == 4
11471151
11481152 result = document_store .get_metadata_field_min_max ("rating" ) # type:ignore[attr-defined]
11491153
@@ -1173,15 +1177,16 @@ def test_get_metadata_field_min_max_empty_collection(document_store: DocumentSto
11731177 @staticmethod
11741178 def test_get_metadata_field_min_max_meta_prefix (document_store : DocumentStore ):
11751179 """Test get_metadata_field_min_max() with field names that include 'meta.' prefix."""
1180+ # The min and max of each field are deliberately not the first or last written values.
11761181 docs = [
1177- Document (content = "Doc 1" , meta = {"priority" : 1 , "age" : 10 }),
1178- Document (content = "Doc 2" , meta = {"priority" : 5 , "age" : 20 }),
1179- Document (content = "Doc 3" , meta = {"priority" : 3 , "age" : 15 }),
1180- Document (content = "Doc 4" , meta = {"priority" : 10 , "age" : 5 }),
1182+ Document (content = "Doc 1" , meta = {"priority" : 5 , "age" : 10 }),
1183+ Document (content = "Doc 2" , meta = {"priority" : 1 , "age" : 20 }),
1184+ Document (content = "Doc 3" , meta = {"priority" : 10 , "age" : 15 }),
1185+ Document (content = "Doc 4" , meta = {"priority" : 3 , "age" : 5 }),
11811186 Document (content = "Doc 6" , meta = {"rating" : 10.5 }),
11821187 Document (content = "Doc 7" , meta = {"rating" : 20.3 }),
1183- Document (content = "Doc 8" , meta = {"rating" : 15.7 }),
1184- Document (content = "Doc 9" , meta = {"rating" : 5.2 }),
1188+ Document (content = "Doc 8" , meta = {"rating" : 5.2 }),
1189+ Document (content = "Doc 9" , meta = {"rating" : 15.7 }),
11851190 ]
11861191 document_store .write_documents (docs )
11871192
@@ -1233,6 +1238,7 @@ def test_get_metadata_field_unique_values_basic(document_store: DocumentStore):
12331238
12341239 values = result [0 ] if isinstance (result , tuple ) else result
12351240 assert isinstance (values , list )
1241+ assert len (values ) == 3 # the returned values must not contain duplicates
12361242 assert set (values ) == {"A" , "B" , "C" }
12371243 if isinstance (result , tuple ) and len (result ) >= 2 and isinstance (result [1 ], int ):
12381244 assert result [1 ] == 3
0 commit comments