All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openmetadata.service.search.indexes.DashboardDataModelIndex Maven / Gradle / Ivy

There is a newer version: 1.5.11
Show newest version
package org.openmetadata.service.search.indexes;

import static org.openmetadata.service.search.EntityBuilderConstant.COLUMNS_NAME_KEYWORD;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.openmetadata.schema.entity.data.DashboardDataModel;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.ParseTags;
import org.openmetadata.service.search.models.FlattenColumn;
import org.openmetadata.service.search.models.SearchSuggest;

public record DashboardDataModelIndex(DashboardDataModel dashboardDataModel)
    implements ColumnIndex {

  @Override
  public List getSuggest() {
    List suggest = new ArrayList<>();
    suggest.add(SearchSuggest.builder().input(dashboardDataModel.getName()).weight(10).build());
    suggest.add(
        SearchSuggest.builder()
            .input(dashboardDataModel.getFullyQualifiedName())
            .weight(5)
            .build());
    return suggest;
  }

  @Override
  public Object getEntity() {
    return dashboardDataModel;
  }

  public Map buildSearchIndexDocInternal(Map doc) {
    List columnSuggest = new ArrayList<>();
    Set> tagsWithChildren = new HashSet<>();
    List columnsWithChildrenName = new ArrayList<>();
    if (dashboardDataModel.getColumns() != null) {
      List cols = new ArrayList<>();
      parseColumns(dashboardDataModel.getColumns(), cols, null);
      for (FlattenColumn col : cols) {
        columnSuggest.add(SearchSuggest.builder().input(col.getName()).weight(5).build());
        columnsWithChildrenName.add(col.getName());
        if (col.getTags() != null) {
          tagsWithChildren.add(col.getTags());
        }
      }
      doc.put("columnNames", columnsWithChildrenName);
    }
    ParseTags parseTags =
        new ParseTags(Entity.getEntityTags(Entity.DASHBOARD_DATA_MODEL, dashboardDataModel));
    tagsWithChildren.add(parseTags.getTags());
    List flattenedTagList =
        tagsWithChildren.stream()
            .flatMap(List::stream)
            .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
    Map commonAttributes =
        getCommonAttributesMap(dashboardDataModel, Entity.DASHBOARD_DATA_MODEL);
    doc.putAll(commonAttributes);
    doc.put("tags", flattenedTagList);
    doc.put("column_suggest", columnSuggest);
    doc.put("tier", parseTags.getTierTag());
    doc.put("service", getEntityWithDisplayName(dashboardDataModel.getService()));
    doc.put("lineage", SearchIndex.getLineageData(dashboardDataModel.getEntityReference()));
    doc.put("domain", getEntityWithDisplayName(dashboardDataModel.getDomain()));
    return doc;
  }

  public static Map getFields() {
    Map fields = SearchIndex.getDefaultFields();
    fields.put(COLUMNS_NAME_KEYWORD, 10.0f);
    fields.put("columns.name", 2.0f);
    fields.put("columns.displayName", 1.0f);
    fields.put("columns.description", 1.0f);
    fields.put("columns.children.name", 2.0f);
    return fields;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy