Skip to content

Commit 5279454

Browse files
authored
feat(search): make OKF document descriptions full-text searchable (#21877)
1 parent fd2b706 commit 5279454

7 files changed

Lines changed: 129 additions & 3 deletions

File tree

‎metadata-ingestion/docs/sources/github/github-documents_post.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ For each concept the source:
106106
- maps `title` to the document title, `type` to its subtype, and `owners`, `tags`, and `glossary_terms` to native associations;
107107
- stores `status`, `staleAfter`, `generated`, and `verified` as OKF metadata only. These fields do not change the document's native status, owners, or permissions.
108108

109-
The file location is the bundle location followed by its root path and `conceptId` with `.md` appended, joining path components with slashes. The GitHub document source and existing `github_*` custom properties still retain the import location and revision details. `mappingVersion` is recorded in value attribution and source hashes, rather than in `okfProperties`. Bundle location and root path support exact search through `okfBundleLocation` and `okfBundleRootPath`. `okfConceptId` and `okfDeclaredId` also support case-insensitive and text search on Search V3; `okfType` and `okfStatus` provide type and lifecycle filters.
109+
The file location is the bundle location followed by its root path and `conceptId` with `.md` appended, joining path components with slashes. The GitHub document source and existing `github_*` custom properties still retain the import location and revision details. `mappingVersion` is recorded in value attribution and source hashes, rather than in `okfProperties`. Bundle location and root path support exact search through `okfBundleLocation` and `okfBundleRootPath`. `okfConceptId` and `okfDeclaredId` also support case-insensitive and text search on Search V3; `okfType` and `okfStatus` provide type and lifecycle filters. The frontmatter `description` is full-text searchable and part of the default search, like other assets' descriptions.
110110

111111
GraphQL exposes a read-only, nullable `okfProperties.frontmatter` field containing the keys as a JSON object parsed from `raw` when read. It returns null if parsing fails. Dates remain strings. Ingestion validates JSON-compatible YAML values, rejecting duplicate keys, non-string keys, anchors, and aliases, but stores no JSON copy. Frontmatter blocks are limited to 64 KiB, including delimiters. Unsafe or oversized frontmatter is imported as plain text with a parse warning. Unknown keys remain in `raw`.
112112

‎metadata-io/src/test/java/com/linkedin/metadata/search/elasticsearch/index/entity/v3/V3SearchFieldModelTest.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ public void testSearchReadsTheSharedMappingFieldModel() {
6464
assertSame(document, dataset);
6565
assertEquals(description.getPath(), "description");
6666
assertTrue(description.getSubfields().containsAll(Set.of("text", "stemmed")));
67-
assertFalse(
67+
assertTrue(
6868
V3SearchFieldModel.forIndexGroup(REGISTRY, List.of(REGISTRY.getEntitySpec("document")))
6969
.resolver()
7070
.supports("description", Intent.FULL_TEXT));
71+
assertFalse(
72+
V3SearchFieldModel.forIndexGroup(
73+
REGISTRY, List.of(REGISTRY.getEntitySpec("dataHubIngestionSource")))
74+
.resolver()
75+
.supports("description", Intent.FULL_TEXT));
7176
assertEquals(document.exactPath("id", Intent.EXACT), "id");
7277
assertEquals(document.exactPath("domains.keyword", Intent.FILTER), "domains_urn");
7378
assertEquals(document.exactPath("id", Intent.FILTER), "id");

‎metadata-io/src/test/java/com/linkedin/metadata/search/elasticsearch/index/entity/v3/V3SearchFieldsTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public void testMatchedFieldSourcesKeepOnlyNamesAndTagsOfOther() {
153153
Map<String, List<String>> documentFields =
154154
V3SearchFields.fullTextFields(List.of(REGISTRY.getEntitySpec("document")));
155155
assertTrue(documentFields.containsKey("text"), documentFields.toString());
156+
assertEquals(
157+
documentFields.get(DESCRIPTION), List.of("description"), documentFields.toString());
156158
assertFalse(documentFields.get(OTHER).contains("text"), documentFields.toString());
157159
List<String> freeText = List.of("semanticText", "customProperties");
158160
assertTrue(documentFields.get(OTHER).containsAll(freeText), documentFields.toString());

‎metadata-io/src/test/java/com/linkedin/metadata/search/query/request/SearchQueryBuilderTest.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,21 @@ public void testGetStandardFieldsEntitySpec() {
404404
.collect(Collectors.toSet())));
405405
}
406406

407+
@Test
408+
public void testDocumentStandardFieldsIncludeOkfDescription() {
409+
Set<String> fieldNames =
410+
TEST_CUSTOM_BUILDER
411+
.getStandardFields(
412+
opContext,
413+
ImmutableList.of(opContext.getEntityRegistry().getEntitySpec("document")))
414+
.stream()
415+
.map(SearchFieldConfig::fieldName)
416+
.collect(Collectors.toSet());
417+
assertTrue(
418+
fieldNames.containsAll(Set.of("description", "description.delimited")),
419+
fieldNames.toString());
420+
}
421+
407422
@Test
408423
public void testGetStandardFields() {
409424
Set<SearchFieldConfig> fieldConfigs =

‎metadata-io/src/test/resources/search/template/golden/field-manifest.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@
555555
}, {
556556
"boost" : 0.5,
557557
"field" : "tags"
558+
}, {
559+
"boost" : 1.0,
560+
"field" : "description"
558561
}, {
559562
"boost" : 0.5,
560563
"field" : "glossaryTerms"

‎metadata-models/src/main/pegasus/com/linkedin/okf/OkfProperties.pdl‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ namespace com.linkedin.okf
22

33
/** An okfProperties without `raw` means the document is not (or no longer) an OKF concept; readers treat it like an absent aspect. When `raw` is present, `bundle`, `conceptId` and `type` are always set. */
44
@Aspect = {
5-
"name": "okfProperties"
5+
"name": "okfProperties",
6+
"schemaVersion": 2
67
}
78
record OkfProperties {
89
/** Bundle identity and format version. Concept identifiers are scoped to this bundle. */
@@ -57,6 +58,19 @@ record OkfProperties {
5758
type: optional string
5859

5960
/** Description declared in frontmatter. */
61+
@Searchable = {
62+
"fieldType": "TEXT",
63+
"hasValuesFieldName": "hasDescription",
64+
"v3": {
65+
"queryByDefault": true,
66+
"searchLabel": "description",
67+
"mappings": [
68+
{ "type": "KEYWORD", "index": false, "docValues": false },
69+
{ "subfield": "text", "type": "TEXT" },
70+
{ "subfield": "stemmed", "type": "STEMMED" }
71+
]
72+
}
73+
}
6074
description: optional string
6175

6276
/** Lifecycle status as written, conventionally draft, stable, or deprecated. */
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

Comments
 (0)