Commit 1e8fa7e5 by Mandar Ambawane Committed by Sarath Subramanian

ATLAS-3709 Issues with quick search/suggestions in conjunction with Business Metadata attributes

parent 3ff785a8
......@@ -92,7 +92,7 @@ public class ChangedTypeDefs {
}
public boolean hasBusinessMetadataDef() {
return hasBusinessMetadataDef(createdTypeDefs) || hasEntityDef(updatedTypeDefs) || hasEntityDef(deletedTypeDefs);
return hasBusinessMetadataDef(createdTypeDefs) || hasBusinessMetadataDef(updatedTypeDefs) || hasBusinessMetadataDef(deletedTypeDefs);
}
private boolean hasBusinessMetadataDef(List<? extends AtlasBaseTypeDef> typeDefs) {
......
......@@ -980,22 +980,9 @@ public class AtlasTypeRegistry {
new Exception().fillInStackTrace());
} else if (typeRegistryUpdateLock.getHoldCount() == 1) {
if (ttr != null && commitUpdates) {
// copy indexName for entity attributes from current typeRegistry to new one
for (AtlasEntityType ttrEntityType : ttr.getAllEntityTypes()) {
AtlasEntityType currEntityType = typeRegistry.getEntityTypeByName(ttrEntityType.getTypeName());
if (currEntityType != null) { // ttrEntityType could be a new type introduced
for (AtlasAttribute attribute : ttrEntityType.getAllAttributes().values()) {
if (StringUtils.isEmpty(attribute.getIndexFieldName())) {
AtlasAttribute currAttribute = currEntityType.getAttribute(attribute.getName());
if (currAttribute != null) {
attribute.setIndexFieldName(currAttribute.getIndexFieldName());
}
}
}
}
}
// copy indexName for attributes from current typeRegistry to new one
copyIndexNameFromCurrent(ttr.getAllEntityTypes());
copyIndexNameFromCurrent(ttr.getAllBusinessMetadataTypes());
typeRegistry.registryData = ttr.registryData;
}
......@@ -1018,6 +1005,34 @@ public class AtlasTypeRegistry {
LOG.debug("<== releaseTypeRegistryForUpdate()");
}
private void copyIndexNameFromCurrent(Collection<? extends AtlasStructType> ttrTypes) {
for (AtlasStructType ttrType : ttrTypes) {
final AtlasStructType currType;
if (ttrType instanceof AtlasEntityType) {
currType = typeRegistry.getEntityTypeByName(ttrType.getTypeName());
} else if (ttrType instanceof AtlasBusinessMetadataType) {
currType = typeRegistry.getBusinessMetadataTypeByName(ttrType.getTypeName());
} else {
currType = null;
}
if (currType == null) { // ttrType could be a new type introduced
continue;
}
for (AtlasAttribute ttrAttribute : ttrType.getAllAttributes().values()) {
if (StringUtils.isEmpty(ttrAttribute.getIndexFieldName())) {
AtlasAttribute currAttribute = currType.getAttribute(ttrAttribute.getName());
if (currAttribute != null) {
ttrAttribute.setIndexFieldName(currAttribute.getIndexFieldName());
}
}
}
}
}
}
}
......
......@@ -209,14 +209,18 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
LOG.debug("Type definition load completed. Informing the completion to IndexChangeListeners.");
}
Collection<AtlasEntityDef> entityDefs = typeRegistry.getAllEntityDefs();
ChangedTypeDefs changedTypeDefs = new ChangedTypeDefs(null, new ArrayList<>(entityDefs), null);
ChangedTypeDefs changedTypeDefs = null;
AtlasGraphManagement management = null;
try {
management = provider.get().getManagementSystem();
//resolve index fields names for the new entity attributes.
changedTypeDefs = new ChangedTypeDefs(null, new ArrayList<>(typeRegistry.getAllEntityDefs()), null);
resolveIndexFieldNames(management, changedTypeDefs);
//resolve index fields names for the new business metadata attributes.
changedTypeDefs = new ChangedTypeDefs(null, new ArrayList<>(typeRegistry.getAllBusinessMetadataDefs()), null);
resolveIndexFieldNames(management, changedTypeDefs);
//Commit indexes
......@@ -382,19 +386,13 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
resolveIndexFieldNames(managementSystem, businessMetadataType);
} else {
LOG.debug("Ignoring the non-entity type definition {}", baseTypeDef.getName());
}
LOG.debug("Ignoring type definition {}", baseTypeDef.getName());
}
}
private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, AtlasEntityType entityType) {
for(AtlasAttribute attribute: entityType.getAllAttributes().values()) {
resolveIndexFieldName(managementSystem, attribute);
}
}
private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, AtlasBusinessMetadataType businessMetadataType) {
for (AtlasAttribute attribute : businessMetadataType.getAllAttributes().values()) {
private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, AtlasStructType structType) {
for(AtlasAttribute attribute: structType.getAllAttributes().values()) {
resolveIndexFieldName(managementSystem, attribute);
}
}
......
......@@ -25,6 +25,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient;
import org.apache.atlas.type.AtlasBusinessMetadataType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.util.AtlasRepositoryConfiguration;
......@@ -119,57 +120,38 @@ public class SolrIndexHelper implements IndexChangeListener {
private Map<String, Integer> geIndexFieldNamesWithSearchWeights() {
Map<String, Integer> ret = new HashMap<>();
Collection<AtlasEntityType> entityTypes = typeRegistry.getAllEntityTypes();
Collection<AtlasBusinessMetadataType> businessMetadataTypes = typeRegistry.getAllBusinessMetadataTypes();
//the following properties are specially added manually.
//as, they don't come in the entity definitions as attributes.
ret.put(typeRegistry.getIndexFieldName(CLASSIFICATION_TEXT_KEY), SEARCHWEIGHT_FOR_CLASSIFICATIONS);
ret.put(typeRegistry.getIndexFieldName(LABELS_PROPERTY_KEY), SEARCHWEIGHT_FOR_LABELS);
ret.put(typeRegistry.getIndexFieldName(CUSTOM_ATTRIBUTES_PROPERTY_KEY), SEARCHWEIGHT_FOR_CUSTOM_ATTRS);
ret.put(typeRegistry.getIndexFieldName(TYPE_NAME_PROPERTY_KEY), SEARCHWEIGHT_FOR_TYPENAME);
if (!CollectionUtils.isNotEmpty(entityTypes) && CollectionUtils.isEmpty(businessMetadataTypes)) {
return ret;
}
for (AtlasEntityType entityType : entityTypes) {
for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
if (entityType.isInternalType()) {
continue;
}
processEntityType(ret, entityType);
processType(ret, entityType);
}
for(AtlasBusinessMetadataType businessMetadataType : businessMetadataTypes){
processBusinessMetadataType(ret, businessMetadataType);
for (AtlasBusinessMetadataType businessMetadataType : typeRegistry.getAllBusinessMetadataTypes()) {
processType(ret, businessMetadataType);
}
return ret;
}
private void processBusinessMetadataType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasBusinessMetadataType businessMetadataType) {
List<AtlasAttributeDef> attributes = businessMetadataType.getBusinessMetadataDef().getAttributeDefs();
private void processType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasStructType structType) {
List<AtlasAttributeDef> attributes = structType.getStructDef().getAttributeDefs();
if (CollectionUtils.isNotEmpty(attributes)) {
for (AtlasAttributeDef attribute : attributes) {
processAttribute(indexFieldNameWithSearchWeights, businessMetadataType.getAttribute(attribute.getName()));
}
} else {
LOG.debug("No attributes are defined for BusinessMetadata {}", businessMetadataType.getTypeName());
}
}
private void processEntityType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasEntityType entityType) {
List<AtlasAttributeDef> attributes = entityType.getEntityDef().getAttributeDefs();
if(CollectionUtils.isNotEmpty(attributes)) {
for (AtlasAttributeDef attribute : attributes) {
processAttribute(indexFieldNameWithSearchWeights, entityType.getAttribute(attribute.getName()));
processAttribute(indexFieldNameWithSearchWeights, structType.getAttribute(attribute.getName()));
}
} else {
LOG.debug("No attributes are defined for entity {}", entityType.getTypeName());
LOG.debug("No attributes are defined for type {}", structType.getTypeName());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment