Commit df8502ea by Mandar Ambawane Committed by Sarath Subramanian

ATLAS-3675 Enable quick search and suggestions for business metadata attributes

parent dff690a0
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.listener; package org.apache.atlas.listener;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -89,4 +90,24 @@ public class ChangedTypeDefs { ...@@ -89,4 +90,24 @@ public class ChangedTypeDefs {
return ret; return ret;
} }
public boolean hasBusinessMetadataDef() {
return hasBusinessMetadataDef(createdTypeDefs) || hasEntityDef(updatedTypeDefs) || hasEntityDef(deletedTypeDefs);
}
private boolean hasBusinessMetadataDef(List<? extends AtlasBaseTypeDef> typeDefs) {
boolean ret = false;
if (CollectionUtils.isNotEmpty(typeDefs)) {
for (AtlasBaseTypeDef typeDef : typeDefs) {
if (typeDef instanceof AtlasBusinessMetadataDef) {
ret = true;
break;
}
}
}
return ret;
}
} }
...@@ -377,6 +377,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -377,6 +377,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(baseTypeDef.getName()); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(baseTypeDef.getName());
resolveIndexFieldNames(managementSystem, entityType); resolveIndexFieldNames(managementSystem, entityType);
} else if(TypeCategory.BUSINESS_METADATA.equals(baseTypeDef.getCategory())) {
AtlasBusinessMetadataType businessMetadataType = typeRegistry.getBusinessMetadataTypeByName(baseTypeDef.getName());
resolveIndexFieldNames(managementSystem, businessMetadataType);
} else { } else {
LOG.debug("Ignoring the non-entity type definition {}", baseTypeDef.getName()); LOG.debug("Ignoring the non-entity type definition {}", baseTypeDef.getName());
} }
...@@ -389,6 +393,12 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang ...@@ -389,6 +393,12 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
} }
} }
private void resolveIndexFieldNames(AtlasGraphManagement managementSystem, AtlasBusinessMetadataType businessMetadataType) {
for (AtlasAttribute attribute : businessMetadataType.getAllAttributes().values()) {
resolveIndexFieldName(managementSystem, attribute);
}
}
private void resolveIndexFieldName(AtlasGraphManagement managementSystem, AtlasAttribute attribute) { private void resolveIndexFieldName(AtlasGraphManagement managementSystem, AtlasAttribute attribute) {
try { try {
if (attribute.getIndexFieldName() == null && TypeCategory.PRIMITIVE.equals(attribute.getAttributeType().getTypeCategory())) { if (attribute.getIndexFieldName() == null && TypeCategory.PRIMITIVE.equals(attribute.getAttributeType().getTypeCategory())) {
......
...@@ -23,6 +23,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; ...@@ -23,6 +23,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient; import org.apache.atlas.repository.graphdb.AtlasGraphIndexClient;
import org.apache.atlas.type.AtlasBusinessMetadataType;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute; import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
...@@ -67,7 +68,7 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -67,7 +68,7 @@ public class SolrIndexHelper implements IndexChangeListener {
@Override @Override
public void onChange(ChangedTypeDefs changedTypeDefs) { public void onChange(ChangedTypeDefs changedTypeDefs) {
if (!AtlasRepositoryConfiguration.isFreeTextSearchEnabled() || if (!AtlasRepositoryConfiguration.isFreeTextSearchEnabled() ||
changedTypeDefs == null || !changedTypeDefs.hasEntityDef()) { // nothing to do if there are no changes to entity-defs changedTypeDefs == null || !(changedTypeDefs.hasEntityDef() || changedTypeDefs.hasBusinessMetadataDef())) { // nothing to do if there are no changes to entity-defs
return; return;
} }
if(initializationCompleted) { if(initializationCompleted) {
...@@ -119,6 +120,7 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -119,6 +120,7 @@ public class SolrIndexHelper implements IndexChangeListener {
private Map<String, Integer> geIndexFieldNamesWithSearchWeights() { private Map<String, Integer> geIndexFieldNamesWithSearchWeights() {
Map<String, Integer> ret = new HashMap<>(); Map<String, Integer> ret = new HashMap<>();
Collection<AtlasEntityType> entityTypes = typeRegistry.getAllEntityTypes(); Collection<AtlasEntityType> entityTypes = typeRegistry.getAllEntityTypes();
Collection<AtlasBusinessMetadataType> businessMetadataTypes = typeRegistry.getAllBusinessMetadataTypes();
//the following properties are specially added manually. //the following properties are specially added manually.
//as, they don't come in the entity definitions as attributes. //as, they don't come in the entity definitions as attributes.
...@@ -128,7 +130,7 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -128,7 +130,7 @@ public class SolrIndexHelper implements IndexChangeListener {
ret.put(typeRegistry.getIndexFieldName(CUSTOM_ATTRIBUTES_PROPERTY_KEY), SEARCHWEIGHT_FOR_CUSTOM_ATTRS); ret.put(typeRegistry.getIndexFieldName(CUSTOM_ATTRIBUTES_PROPERTY_KEY), SEARCHWEIGHT_FOR_CUSTOM_ATTRS);
ret.put(typeRegistry.getIndexFieldName(TYPE_NAME_PROPERTY_KEY), SEARCHWEIGHT_FOR_TYPENAME); ret.put(typeRegistry.getIndexFieldName(TYPE_NAME_PROPERTY_KEY), SEARCHWEIGHT_FOR_TYPENAME);
if (!CollectionUtils.isNotEmpty(entityTypes)) { if (!CollectionUtils.isNotEmpty(entityTypes) && CollectionUtils.isEmpty(businessMetadataTypes)) {
return ret; return ret;
} }
...@@ -140,9 +142,25 @@ public class SolrIndexHelper implements IndexChangeListener { ...@@ -140,9 +142,25 @@ public class SolrIndexHelper implements IndexChangeListener {
processEntityType(ret, entityType); processEntityType(ret, entityType);
} }
for(AtlasBusinessMetadataType businessMetadataType : businessMetadataTypes){
processBusinessMetadataType(ret, businessMetadataType);
}
return ret; return ret;
} }
private void processBusinessMetadataType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasBusinessMetadataType businessMetadataType) {
List<AtlasAttributeDef> attributes = businessMetadataType.getBusinessMetadataDef().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) { private void processEntityType(Map<String, Integer> indexFieldNameWithSearchWeights, AtlasEntityType entityType) {
List<AtlasAttributeDef> attributes = entityType.getEntityDef().getAttributeDefs(); List<AtlasAttributeDef> attributes = entityType.getEntityDef().getAttributeDefs();
......
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