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

org.openmetadata.service.search.indexes.ContainerIndex 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.DATA_MODEL_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.Container;
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 ContainerIndex(Container container) implements ColumnIndex {
  @Override
  public List getSuggest() {
    List suggest = new ArrayList<>();
    suggest.add(SearchSuggest.builder().input(container.getFullyQualifiedName()).weight(5).build());
    suggest.add(SearchSuggest.builder().input(container.getName()).weight(10).build());
    return suggest;
  }

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

  public Map buildSearchIndexDocInternal(Map doc) {
    List columnSuggest = new ArrayList<>();
    List serviceSuggest = new ArrayList<>();
    Set> tagsWithChildren = new HashSet<>();
    List columnsWithChildrenName = new ArrayList<>();
    if (container.getDataModel() != null && container.getDataModel().getColumns() != null) {
      List cols = new ArrayList<>();
      parseColumns(container.getDataModel().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);
    }
    serviceSuggest.add(
        SearchSuggest.builder().input(container.getService().getName()).weight(5).build());
    ParseTags parseTags = new ParseTags(Entity.getEntityTags(Entity.CONTAINER, container));
    tagsWithChildren.add(parseTags.getTags());
    List flattenedTagList =
        tagsWithChildren.stream()
            .flatMap(List::stream)
            .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);

    Map commonAttributes = getCommonAttributesMap(container, Entity.CONTAINER);
    doc.putAll(commonAttributes);
    doc.put(
        "displayName",
        container.getDisplayName() != null ? container.getDisplayName() : container.getName());
    doc.put("tags", flattenedTagList);
    doc.put("tier", parseTags.getTierTag());
    doc.put("service_suggest", serviceSuggest);
    doc.put("column_suggest", columnSuggest);
    doc.put("serviceType", container.getServiceType());
    doc.put("fullPath", container.getFullPath());
    doc.put("lineage", SearchIndex.getLineageData(container.getEntityReference()));
    doc.put("service", getEntityWithDisplayName(container.getService()));
    return doc;
  }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy