Skip to content

Commit

Permalink
Minor: Add glossary index to SearchIndexFactory (#14690)
Browse files Browse the repository at this point in the history
* Minor: Add glossary index to SearchIndexFactory

* Minor: Add glossary index to SearchIndexFactory
  • Loading branch information
harshach authored Jan 12, 2024
1 parent 99b8e79 commit e786380
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> excludeFields = List.of("changeDescription");

public GlossaryIndex(GlossaryTerm glossaryTerm) {
this.glossaryTerm = glossaryTerm;
public GlossaryIndex(Glossary glossary) {
this.glossary = glossary;
}

public Map<String, Object> buildESDoc() {
Map<String, Object> doc = JsonUtils.getMap(glossaryTerm);
Map<String, Object> doc = JsonUtils.getMap(glossary);
SearchIndexUtils.removeNonIndexableFields(doc, excludeFields);
List<SearchSuggest> 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;
}
}

0 comments on commit e786380

Please sign in to comment.