Repository: usergrid
Updated Branches:
  refs/heads/2.1-release 432c2e9c1 -> 244fa52ee


Fix issue where data from objects nested within an array were not getting 
indexed.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/244fa52e
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/244fa52e
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/244fa52e

Branch: refs/heads/2.1-release
Commit: 244fa52ee2685d0ca68986b5747cd21576738d14
Parents: 432c2e9
Author: Michael Russo <[email protected]>
Authored: Tue Nov 3 11:12:29 2015 -0800
Committer: Michael Russo <[email protected]>
Committed: Tue Nov 3 11:25:38 2015 -0800

----------------------------------------------------------------------
 .../index/impl/EntityMappingParser.java         |  4 ++
 .../index/impl/EntityToMapConverterTest.java    | 48 ++++++++++++++++++++
 2 files changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/244fa52e/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
----------------------------------------------------------------------
diff --git 
a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
 
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
index 63cef04..2c82782 100644
--- 
a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
+++ 
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
@@ -202,11 +202,15 @@ public class EntityMappingParser implements FieldParser {
      */
     private void iterate( final Map<String, ?> map ) {
 
+        lastCollection.push( map );
+
         for ( final Map.Entry<String, ?> jsonField : map.entrySet() ) {
             pushField( jsonField.getKey() );
             visitValue( jsonField.getValue() );
             popField();
         }
+
+        lastCollection.pop();
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/244fa52e/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
----------------------------------------------------------------------
diff --git 
a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
 
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
index c412cf4..7e7c466 100644
--- 
a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
+++ 
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverterTest.java
@@ -650,4 +650,52 @@ public class EntityToMapConverterTest {
 
         assertEquals( "value", field.get( IndexingUtils.FIELD_STRING ) );
     }
+
+    /**
+     * Objects nested within arrays are allowed to be indexed (just not n+1 
nested arrays themselves)
+     */
+    @Test
+    public void testObjectNestedInArray() {
+
+        final ArrayField<Object> array = new ArrayField<>("array");
+
+        // this should not get indexed
+        final ArrayField<Object> nestedArray1 = new 
ArrayField<>("nestedArray");
+        nestedArray1.add("1");
+
+        // this should get indexed
+        final EntityObject nestedObject1 = new EntityObject();
+        final ArrayField<Object> objectArray = new 
ArrayField<>("nestedArrayInObject");
+        final EntityObject nestedObject2 = new EntityObject();
+        nestedObject2.setField(new StringField("nestedKey", "nestedValue"));
+        objectArray.add(nestedObject2);
+        nestedObject1.setField(objectArray);
+
+        array.add(nestedArray1);
+        array.add(nestedObject1);
+
+        Entity rootEntity = new Entity( "test" );
+        rootEntity.setField( array );
+
+        final UUID version = UUIDGenerator.newTimeUUID();
+        EntityUtils.setVersion( rootEntity, version );
+
+        final ApplicationScope scope = new ApplicationScopeImpl( createId( 
"application" ) );
+        final IndexEdge indexEdge =
+            new IndexEdgeImpl( createId( "source" ), "testEdgeType", 
SearchEdge.NodeType.SOURCE, 1000 );
+
+        final Map<String, Object> entityMap = EntityToMapConverter.convert( 
scope, indexEdge, rootEntity );
+        final List<EntityField> fields = ( List<EntityField> ) entityMap.get( 
IndexingUtils.ENTITY_FIELDS );
+
+        // if size of fields is not == 1, then we either
+        // 1) did not index anything or 2) indexed the nested array that 
shouldn't be indexed at all
+        assertEquals( 1, fields.size() );
+        
+        final EntityField field = fields.get( 0 );
+        final String path = 
"array.nestedArrayInObject.nestedKey".toLowerCase();
+
+        assertEquals( path, field.get( IndexingUtils.FIELD_NAME ) );
+
+    }
+
 }

Reply via email to