You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2015/11/03 20:12:35 UTC
usergrid git commit: Fix issue where data from objects nested within
an array were not getting indexed.
Repository: usergrid
Updated Branches:
refs/heads/USERGRID-1088 [created] 5772ebbd4
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/5772ebbd
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/5772ebbd
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/5772ebbd
Branch: refs/heads/USERGRID-1088
Commit: 5772ebbd4da8077f1451f412f71bf189a854a0a8
Parents: 432c2e9
Author: Michael Russo <mi...@gmail.com>
Authored: Tue Nov 3 11:12:29 2015 -0800
Committer: Michael Russo <mi...@gmail.com>
Committed: Tue Nov 3 11:12:29 2015 -0800
----------------------------------------------------------------------
.../index/impl/EntityMappingParser.java | 4 ++
.../index/impl/EntityToMapConverterTest.java | 56 ++++++++++++++++++++
2 files changed, 60 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/5772ebbd/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/5772ebbd/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..32c17f3 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,60 @@ 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 );
+
+ assertEquals( 1, fields.size() );
+
+
+ final EntityField field = fields.get( 0 );
+
+ final String path = "array.nestedArrayInObject.nestedKey".toLowerCase();
+
+ assertEquals( path, field.get( IndexingUtils.FIELD_NAME ) );
+
+ }
+
}