|
19 | 19 | from haystack.dataclasses.document import Document |
20 | 20 | from haystack.errors import FilterError |
21 | 21 | from haystack.testing.document_store import ( |
| 22 | + CountDocumentsByFilterTest, |
22 | 23 | CountDocumentsTest, |
| 24 | + CountUniqueMetadataByFilterTest, |
23 | 25 | DeleteAllTest, |
24 | 26 | DeleteByFilterTest, |
25 | 27 | DeleteDocumentsTest, |
26 | 28 | FilterableDocsFixtureMixin, |
27 | 29 | FilterDocumentsTest, |
28 | | - UpdateByFilterTest, |
29 | | - WriteDocumentsTest, |
30 | | - CountDocumentsByFilterTest, |
31 | | - CountUniqueMetadataByFilterTest, |
32 | | - GetMetadataFieldsInfoTest, |
33 | 30 | GetMetadataFieldMinMaxTest, |
| 31 | + GetMetadataFieldsInfoTest, |
34 | 32 | GetMetadataFieldUniqueValuesTest, |
| 33 | + UpdateByFilterTest, |
| 34 | + WriteDocumentsTest, |
35 | 35 | ) |
36 | 36 | from haystack.utils.auth import EnvVarSecret, Secret |
37 | 37 |
|
@@ -261,80 +261,6 @@ def _build_mock_document_store_with_schema(index_fields): |
261 | 261 | return store, search_client, index_client |
262 | 262 |
|
263 | 263 |
|
264 | | -def test_count_documents_by_filter(): |
265 | | - index_fields = [ |
266 | | - SimpleField(name="id", type=SearchFieldDataType.String, key=True, filterable=True), |
267 | | - SearchableField(name="content", type=SearchFieldDataType.String), |
268 | | - SimpleField(name="category", type=SearchFieldDataType.String, filterable=True), |
269 | | - ] |
270 | | - document_store, search_client, _ = _build_mock_document_store_with_schema(index_fields) |
271 | | - count_result = Mock() |
272 | | - count_result.get_count.return_value = 3 |
273 | | - search_client.search.return_value = count_result |
274 | | - |
275 | | - count = document_store.count_documents_by_filter({"field": "meta.category", "operator": "==", "value": "news"}) |
276 | | - |
277 | | - assert count == 3 |
278 | | - search_client.search.assert_called_once() |
279 | | - assert search_client.search.call_args.kwargs["include_total_count"] is True |
280 | | - |
281 | | - |
282 | | -def test_count_unique_metadata_by_filter(): |
283 | | - index_fields = [ |
284 | | - SimpleField(name="id", type=SearchFieldDataType.String, key=True, filterable=True), |
285 | | - SearchableField(name="content", type=SearchFieldDataType.String), |
286 | | - SimpleField(name="category", type=SearchFieldDataType.String, filterable=True), |
287 | | - SimpleField(name="status", type=SearchFieldDataType.String, filterable=True), |
288 | | - ] |
289 | | - document_store, search_client, _ = _build_mock_document_store_with_schema(index_fields) |
290 | | - search_client.search.return_value = [ |
291 | | - {"category": "news", "status": "draft"}, |
292 | | - {"category": "docs", "status": "draft"}, |
293 | | - {"category": "news", "status": "published"}, |
294 | | - ] |
295 | | - |
296 | | - counts = document_store.count_unique_metadata_by_filter( |
297 | | - filters={"field": "meta.status", "operator": "!=", "value": "archived"}, |
298 | | - metadata_fields=["meta.category", "status"], |
299 | | - ) |
300 | | - |
301 | | - assert counts == {"category": 2, "status": 2} |
302 | | - |
303 | | - |
304 | | -def test_get_metadata_fields_info(): |
305 | | - index_fields = [ |
306 | | - SimpleField(name="id", type=SearchFieldDataType.String, key=True, filterable=True), |
307 | | - SearchableField(name="content", type=SearchFieldDataType.String), |
308 | | - SimpleField(name="category", type=SearchFieldDataType.String, filterable=True), |
309 | | - SimpleField(name="status", type=SearchFieldDataType.String, filterable=True), |
310 | | - SimpleField(name="priority", type=SearchFieldDataType.Int32, filterable=True), |
311 | | - ] |
312 | | - document_store, _, _ = _build_mock_document_store_with_schema(index_fields) |
313 | | - |
314 | | - info = document_store.get_metadata_fields_info() |
315 | | - |
316 | | - assert info == { |
317 | | - "content": {"type": "text"}, |
318 | | - "category": {"type": "keyword"}, |
319 | | - "status": {"type": "keyword"}, |
320 | | - "priority": {"type": "long"}, |
321 | | - } |
322 | | - |
323 | | - |
324 | | -def test_get_metadata_field_min_max(): |
325 | | - index_fields = [ |
326 | | - SimpleField(name="id", type=SearchFieldDataType.String, key=True, filterable=True), |
327 | | - SearchableField(name="content", type=SearchFieldDataType.String), |
328 | | - SimpleField(name="priority", type=SearchFieldDataType.Int32, filterable=True), |
329 | | - ] |
330 | | - document_store, search_client, _ = _build_mock_document_store_with_schema(index_fields) |
331 | | - search_client.search.return_value = [{"priority": 10}, {"priority": 2}, {"priority": 7}] |
332 | | - |
333 | | - result = document_store.get_metadata_field_min_max("meta.priority") |
334 | | - |
335 | | - assert result == {"min": 2, "max": 10} |
336 | | - |
337 | | - |
338 | 264 | def test_get_metadata_field_unique_values(): |
339 | 265 | index_fields = [ |
340 | 266 | SimpleField(name="id", type=SearchFieldDataType.String, key=True, filterable=True), |
|
0 commit comments