Skip to content
Merged
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
19 changes: 11 additions & 8 deletions haystack/testing/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,24 +1052,27 @@ def test_count_unique_metadata_by_filter_with_filter(document_store: DocumentSto

@staticmethod
def test_count_unique_metadata_by_filter_with_multiple_filters(document_store: DocumentStore):
"""Test counting with multiple filters"""
"""Test count_unique_metadata_by_filter() with multiple filters."""
docs = [
Document(content="Doc 1", meta={"category": "A", "year": 2023}),
Document(content="Doc 2", meta={"category": "A", "year": 2024}),
Document(content="Doc 3", meta={"category": "B", "year": 2023}),
Document(content="Doc 4", meta={"category": "B", "year": 2024}),
Document(content="Doc 1", meta={"category": "B", "year": 2023, "status": "draft"}),
Document(content="Doc 2", meta={"category": "B", "year": 2023, "status": "draft"}),
Document(content="Doc 3", meta={"category": "B", "year": 2023, "status": "published"}),
Document(content="Doc 4", meta={"category": "B", "year": 2024, "status": "draft"}),
]
document_store.write_documents(docs)
count = document_store.count_documents_by_filter( # type:ignore[attr-defined]
# The compound filter matches three documents with duplicated values, so the counts only come
# out right when the store both applies the filter and properly counts the values.
counts = document_store.count_unique_metadata_by_filter( # type:ignore[attr-defined]
filters={
"operator": "AND",
"conditions": [
{"field": "meta.category", "operator": "==", "value": "B"},
{"field": "meta.year", "operator": "==", "value": 2023},
],
}
},
metadata_fields=["status", "year"],
)
assert count == 1
assert counts == {"status": 2, "year": 1}


class GetMetadataFieldsInfoTest:
Expand Down
14 changes: 8 additions & 6 deletions haystack/testing/document_store_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,15 @@ async def test_count_unique_metadata_by_filter_async_with_filter(document_store:
async def test_count_unique_metadata_by_filter_async_with_multiple_filters(document_store: AsyncDocumentStore):
"""Test counting unique metadata asynchronously with multiple filters."""
docs = [
Document(content="Doc 1", meta={"category": "A", "year": 2023}),
Document(content="Doc 2", meta={"category": "A", "year": 2024}),
Document(content="Doc 3", meta={"category": "B", "year": 2023}),
Document(content="Doc 4", meta={"category": "B", "year": 2024}),
Document(content="Doc 1", meta={"category": "B", "year": 2023, "status": "draft"}),
Document(content="Doc 2", meta={"category": "B", "year": 2023, "status": "draft"}),
Document(content="Doc 3", meta={"category": "B", "year": 2023, "status": "published"}),
Document(content="Doc 4", meta={"category": "B", "year": 2024, "status": "draft"}),
]
await document_store.write_documents_async(docs)

# The compound filter matches three documents with duplicated values, so the counts only come
# out right when the store both applies the filter and properly counts the values.
counts = await document_store.count_unique_metadata_by_filter_async( # type:ignore[attr-defined]
filters={
"operator": "AND",
Expand All @@ -320,9 +322,9 @@ async def test_count_unique_metadata_by_filter_async_with_multiple_filters(docum
{"field": "meta.year", "operator": "==", "value": 2023},
],
},
metadata_fields=["category", "year"],
metadata_fields=["status", "year"],
)
assert counts == {"category": 1, "year": 1}
assert counts == {"status": 2, "year": 1}


class DeleteByFilterAsyncTest:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Fixed ``CountUniqueMetadataByFilterTest.test_count_unique_metadata_by_filter_with_multiple_filters``
in the document store testing mixins: it called ``count_documents_by_filter`` instead of
``count_unique_metadata_by_filter``. The test now exercises the intended method with a compound
filter, matching its async counterpart.
Loading