From e78638091510c5afc822bbe05d09bbfb2a019fe8 Mon Sep 17 00:00:00 2001 From: Sriharsha Chintalapani Date: Thu, 11 Jan 2024 16:54:40 -0800 Subject: [PATCH] Minor: Add glossary index to SearchIndexFactory (#14690) * Minor: Add glossary index to SearchIndexFactory * Minor: Add glossary index to SearchIndexFactory --- .../service/search/SearchIndexFactory.java | 7 ++++-- .../service/search/indexes/GlossaryIndex.java | 25 +++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexFactory.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexFactory.java index 414c3103fab5..5586a3f2ecb6 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexFactory.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexFactory.java @@ -10,6 +10,7 @@ import org.openmetadata.schema.entity.data.DashboardDataModel; import org.openmetadata.schema.entity.data.Database; import org.openmetadata.schema.entity.data.DatabaseSchema; +import org.openmetadata.schema.entity.data.Glossary; import org.openmetadata.schema.entity.data.GlossaryTerm; import org.openmetadata.schema.entity.data.MlModel; import org.openmetadata.schema.entity.data.Pipeline; @@ -46,6 +47,7 @@ import org.openmetadata.service.search.indexes.DatabaseServiceIndex; import org.openmetadata.service.search.indexes.DomainIndex; import org.openmetadata.service.search.indexes.EntityReportDataIndex; +import org.openmetadata.service.search.indexes.GlossaryIndex; import org.openmetadata.service.search.indexes.GlossaryTermIndex; import org.openmetadata.service.search.indexes.MessagingServiceIndex; import org.openmetadata.service.search.indexes.MetadataServiceIndex; @@ -82,6 +84,7 @@ public SearchIndex buildIndex(String entityType, Object entity) { case Entity.PIPELINE -> new PipelineIndex((Pipeline) entity); case Entity.USER -> new UserIndex((User) entity); case Entity.TEAM -> new TeamIndex((Team) entity); + case Entity.GLOSSARY -> new GlossaryIndex((Glossary) entity); case Entity.GLOSSARY_TERM -> new GlossaryTermIndex((GlossaryTerm) entity); case Entity.MLMODEL -> new MlModelIndex((MlModel) entity); case Entity.TAG -> new TagIndex((Tag) entity); @@ -119,11 +122,11 @@ public SearchIndex buildIndex(String entityType, Object entity) { (ReportData) entity); case Entity.TEST_CASE_RESOLUTION_STATUS -> new TestCaseResolutionStatusIndex( (TestCaseResolutionStatus) entity); - default -> buildExternalIndexes(entityType, entity); + default -> buildExternalIndexes(entityType); }; } - protected SearchIndex buildExternalIndexes(String entityType, Object entity) { + protected SearchIndex buildExternalIndexes(String entityType) { throw new IllegalArgumentException( String.format("Entity Type [%s] is not valid for Index Factory", entityType)); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/GlossaryIndex.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/GlossaryIndex.java index f728edca70a3..3b95738756eb 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/GlossaryIndex.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/GlossaryIndex.java @@ -3,38 +3,37 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; -import org.openmetadata.schema.entity.data.GlossaryTerm; +import org.openmetadata.schema.entity.data.Glossary; import org.openmetadata.service.Entity; import org.openmetadata.service.search.SearchIndexUtils; import org.openmetadata.service.search.models.SearchSuggest; import org.openmetadata.service.util.JsonUtils; public class GlossaryIndex implements SearchIndex { - final GlossaryTerm glossaryTerm; + final Glossary glossary; final List excludeFields = List.of("changeDescription"); - public GlossaryIndex(GlossaryTerm glossaryTerm) { - this.glossaryTerm = glossaryTerm; + public GlossaryIndex(Glossary glossary) { + this.glossary = glossary; } public Map buildESDoc() { - Map doc = JsonUtils.getMap(glossaryTerm); + Map doc = JsonUtils.getMap(glossary); SearchIndexUtils.removeNonIndexableFields(doc, excludeFields); List suggest = new ArrayList<>(); - suggest.add(SearchSuggest.builder().input(glossaryTerm.getName()).weight(5).build()); - if (glossaryTerm.getDisplayName() != null && !glossaryTerm.getDisplayName().isEmpty()) { - suggest.add(SearchSuggest.builder().input(glossaryTerm.getDisplayName()).weight(10).build()); + suggest.add(SearchSuggest.builder().input(glossary.getName()).weight(5).build()); + if (glossary.getDisplayName() != null && !glossary.getDisplayName().isEmpty()) { + suggest.add(SearchSuggest.builder().input(glossary.getDisplayName()).weight(10).build()); } doc.put( "fqnParts", getFQNParts( - glossaryTerm.getFullyQualifiedName(), - suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList()))); + glossary.getFullyQualifiedName(), + suggest.stream().map(SearchSuggest::getInput).toList())); doc.put("suggest", suggest); doc.put("entityType", Entity.GLOSSARY); - doc.put("owner", getEntityWithDisplayName(glossaryTerm.getOwner())); - doc.put("domain", getEntityWithDisplayName(glossaryTerm.getDomain())); + doc.put("owner", getEntityWithDisplayName(glossary.getOwner())); + doc.put("domain", getEntityWithDisplayName(glossary.getDomain())); return doc; } }