mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-27 05:36:33 +08:00
Feat: enhance metadata arranging. (#12745)
### What problem does this PR solve? #11564 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -16,8 +16,8 @@
|
||||
# Although the docs group this under "chunk management," the backend aggregates
|
||||
# Document.meta_fields via document_service#get_metadata_summary and the test
|
||||
# uses update_document, so it belongs with file/document management tests.
|
||||
import pytest
|
||||
from common import metadata_summary, update_document
|
||||
# import pytest
|
||||
#from common import metadata_summary, update_document
|
||||
|
||||
|
||||
def _summary_to_counts(summary):
|
||||
@ -28,25 +28,29 @@ def _summary_to_counts(summary):
|
||||
|
||||
|
||||
class TestMetadataSummary:
|
||||
@pytest.mark.p2
|
||||
def test_metadata_summary_counts(self, HttpApiAuth, add_documents_func):
|
||||
dataset_id, document_ids = add_documents_func
|
||||
payloads = [
|
||||
{"tags": ["foo", "bar"], "author": "alice"},
|
||||
{"tags": ["foo"], "author": "bob"},
|
||||
{"tags": ["bar", "baz"], "author": None},
|
||||
]
|
||||
for doc_id, meta_fields in zip(document_ids, payloads):
|
||||
res = update_document(HttpApiAuth, dataset_id, doc_id, {"meta_fields": meta_fields})
|
||||
assert res["code"] == 0, res
|
||||
pass
|
||||
|
||||
res = metadata_summary(HttpApiAuth, dataset_id)
|
||||
assert res["code"] == 0, res
|
||||
summary = res["data"]["summary"]
|
||||
counts = _summary_to_counts(summary)
|
||||
assert counts["tags"]["foo"] == 2, counts
|
||||
assert counts["tags"]["bar"] == 2, counts
|
||||
assert counts["tags"]["baz"] == 1, counts
|
||||
assert counts["author"]["alice"] == 1, counts
|
||||
assert counts["author"]["bob"] == 1, counts
|
||||
assert "None" not in counts["author"], counts
|
||||
# Alteration of API
|
||||
# TODO
|
||||
#@pytest.mark.p2
|
||||
#def test_metadata_summary_counts(self, HttpApiAuth, add_documents_func):
|
||||
# dataset_id, document_ids = add_documents_func
|
||||
# payloads = [
|
||||
# {"tags": ["foo", "bar"], "author": "alice"},
|
||||
# {"tags": ["foo"], "author": "bob"},
|
||||
# {"tags": ["bar", "baz"], "author": None},
|
||||
# ]
|
||||
# for doc_id, meta_fields in zip(document_ids, payloads):
|
||||
# res = update_document(HttpApiAuth, dataset_id, doc_id, {"meta_fields": meta_fields})
|
||||
# assert res["code"] == 0, res
|
||||
|
||||
# res = metadata_summary(HttpApiAuth, dataset_id)
|
||||
# assert res["code"] == 0, res
|
||||
# summary = res["data"]["summary"]
|
||||
# counts = _summary_to_counts(summary)
|
||||
# assert counts["tags"]["foo"] == 2, counts
|
||||
# assert counts["tags"]["bar"] == 2, counts
|
||||
# assert counts["tags"]["baz"] == 1, counts
|
||||
# assert counts["author"]["alice"] == 1, counts
|
||||
# assert counts["author"]["bob"] == 1, counts
|
||||
# assert "None" not in counts["author"], counts
|
||||
|
||||
Reference in New Issue
Block a user