|
| 1 | +import logging |
| 2 | +from typing import List |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from datahub.ingestion.graph.client import DataHubGraph |
| 7 | +from datahub.metadata.schema_classes import ( |
| 8 | + DocumentStateClass, |
| 9 | + OkfBundleClass, |
| 10 | + OkfPropertiesClass, |
| 11 | +) |
| 12 | +from datahub.metadata.urns import DocumentUrn |
| 13 | +from datahub.sdk.document import Document |
| 14 | +from tests.e2e.utils import delete_urn, unique_suffix, with_test_retry |
| 15 | +from utilities.domains import Domain |
| 16 | + |
| 17 | +logger = logging.getLogger(__name__) |
| 18 | +pytestmark = pytest.mark.domain(Domain.AI) |
| 19 | + |
| 20 | +_SEARCH = """ |
| 21 | + query SearchOkfDocuments($input: SearchAcrossEntitiesInput!) { |
| 22 | + searchAcrossEntities(input: $input) { |
| 23 | + searchResults { entity { urn } } |
| 24 | + } |
| 25 | + } |
| 26 | +""" |
| 27 | + |
| 28 | + |
| 29 | +def _search_document_urns(graph: DataHubGraph, query: str) -> List[str]: |
| 30 | + result = graph.execute_graphql( |
| 31 | + _SEARCH, |
| 32 | + variables={ |
| 33 | + "input": {"types": ["DOCUMENT"], "query": query, "start": 0, "count": 10} |
| 34 | + }, |
| 35 | + ) |
| 36 | + return [ |
| 37 | + hit["entity"]["urn"] for hit in result["searchAcrossEntities"]["searchResults"] |
| 38 | + ] |
| 39 | + |
| 40 | + |
| 41 | +@with_test_retry() |
| 42 | +def _assert_found(graph: DataHubGraph, query: str, document_urn: str) -> None: |
| 43 | + assert document_urn in _search_document_urns(graph, query) |
| 44 | + |
| 45 | + |
| 46 | +def test_okf_description_is_full_text_searchable(graph_client: DataHubGraph) -> None: |
| 47 | + suffix = unique_suffix() |
| 48 | + document_urn = str(DocumentUrn(f"okf-search-{suffix}")) |
| 49 | + # The marker appears only in the OKF description, not in the title or text, |
| 50 | + # so a hit proves the description is indexed and queried by default. |
| 51 | + # Letters only: Search V3 splits letters from digits in a quoted query, which |
| 52 | + # then no longer matches the indexed word. |
| 53 | + marker = "zephyrledger" + suffix.translate( |
| 54 | + str.maketrans("0123456789", "ghijklmnop") |
| 55 | + ) |
| 56 | + try: |
| 57 | + doc = Document.create_document( |
| 58 | + id=DocumentUrn(document_urn).id, |
| 59 | + title="Revenue guide", |
| 60 | + text="How revenue is counted.", |
| 61 | + status=DocumentStateClass.PUBLISHED, |
| 62 | + extra_aspects=[ |
| 63 | + OkfPropertiesClass( |
| 64 | + bundle=OkfBundleClass( |
| 65 | + location="https://github.com/example-org/analytics", |
| 66 | + rootPath=".", |
| 67 | + okfVersion="0.2", |
| 68 | + ), |
| 69 | + conceptId="guides/revenue", |
| 70 | + type="Guide", |
| 71 | + description=f"Reconciles the {marker} quarterly close report", |
| 72 | + raw="---\ntype: Guide\n---\n", |
| 73 | + ) |
| 74 | + ], |
| 75 | + ) |
| 76 | + for mcp in doc.as_mcps(): |
| 77 | + graph_client.emit_mcp(mcp) |
| 78 | + |
| 79 | + _assert_found(graph_client, marker, document_urn) |
| 80 | + # Search V3 sends a quoted query to the exact template, which checks the |
| 81 | + # description only for a query of four or more words. |
| 82 | + _assert_found(graph_client, f'"{marker} quarterly close report"', document_urn) |
| 83 | + finally: |
| 84 | + try: |
| 85 | + delete_urn(graph_client, document_urn) |
| 86 | + except Exception: |
| 87 | + logger.warning("Cleanup failed for %s", document_urn, exc_info=True) |
0 commit comments