ATLAS-1956: AtlasSearchResult should include attributes present in filter criteria

Signed-off-by: Madhan Neethiraj <madhan@apache.org>
diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
index c7a624f..dbe11a6 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -420,6 +420,10 @@
                 resultAttributes.addAll(searchParameters.getAttributes());
             }
 
+            if (CollectionUtils.isNotEmpty(context.getEntityAttributes())) {
+                resultAttributes.addAll(context.getEntityAttributes());
+            }
+
             for (String resultAttribute : resultAttributes) {
                 AtlasAttribute attribute = context.getEntityType().getAttribute(resultAttribute);
 
diff --git a/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java b/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
index 2125d61..55a07f3 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
@@ -27,6 +27,7 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 
+import java.util.HashSet;
 import java.util.Set;
 
 
@@ -35,6 +36,7 @@
     private final AtlasTypeRegistry       typeRegistry;
     private final AtlasGraph              graph;
     private final Set<String>             indexedKeys;
+    private final Set<String>             entityAttributes;
     private final AtlasEntityType         entityType;
     private final AtlasClassificationType classificationType;
     private       SearchProcessor         searchProcessor;
@@ -45,6 +47,7 @@
         this.typeRegistry       = typeRegistry;
         this.graph              = graph;
         this.indexedKeys        = indexedKeys;
+        this.entityAttributes   = new HashSet<>();
         this.entityType         = typeRegistry.getEntityTypeByName(searchParameters.getTypeName());
         this.classificationType = typeRegistry.getClassificationTypeByName(searchParameters.getClassification());
 
@@ -70,6 +73,8 @@
 
     public Set<String> getIndexedKeys() { return indexedKeys; }
 
+    public Set<String> getEntityAttributes() { return entityAttributes; }
+
     public AtlasEntityType getEntityType() { return entityType; }
 
     public AtlasClassificationType getClassificationType() { return classificationType; }
diff --git a/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java b/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
index 29430ef..1481809 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
@@ -118,6 +118,11 @@
                     gremlinFiltered.add(attributeName);
                 }
 
+                if (structType instanceof AtlasEntityType) {
+                    // Capture the entity attributes
+                    context.getEntityAttributes().add(attributeName);
+                }
+
                 allAttributes.add(attributeName);
             } catch (AtlasBaseException e) {
                 LOG.warn(e.getMessage());