You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2016/04/08 22:21:17 UTC

[30/36] usergrid git commit: Created a easier to understand algorithm that checks for top level indexing values. Passes existing tests.

Created a easier to understand algorithm that checks for top level indexing values. Passes existing tests.


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

Branch: refs/heads/release-2.1.1
Commit: c748368bd0dae90a0a88015478440105d36faf3a
Parents: 1736ce1
Author: George Reyes <gr...@apache.org>
Authored: Thu Mar 31 17:20:24 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Thu Mar 31 17:20:24 2016 -0700

----------------------------------------------------------------------
 .../index/impl/EntityToMapConverter.java        | 89 ++++++++++++++------
 1 file changed, 63 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/c748368b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
index e9a2075..259b421 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
@@ -109,7 +109,7 @@ public class EntityToMapConverter {
 
         final Set<EntityField> fieldsToBeFiltered =   parser.parse( entityMap );
 
-        //add our fields
+        //add our fields to output entity
         outputEntity.put( ENTITY_FIELDS, fieldsToBeFiltered );
 
         if(fieldsToIndex.isPresent()){
@@ -119,14 +119,15 @@ public class EntityToMapConverter {
             Iterator collectionIterator = mapFields.iterator();
 
             //Loop through all of the fields of the flatted entity and check to see if they should be filtered out.
-            while ( collectionIterator.hasNext() ) {
-                EntityField testedField = ( EntityField ) collectionIterator.next();
+            collectionIterator.forEachRemaining(outputEntityField -> {
+                EntityField testedField = ( EntityField ) outputEntityField;
                 String fieldName = ( String ) ( testedField ).get( "name" );
 
                 if ( !defaultProperties.contains( fieldName ) ) {
-                    iterateThroughMapForFieldsToBeIndexed( defaultProperties, collectionIterator, fieldName );
+                iterateThroughMapForFieldsToBeIndexed( defaultProperties, collectionIterator, fieldName );
                 }
-            }
+            });
+
         }
 
 
@@ -150,12 +151,15 @@ public class EntityToMapConverter {
         boolean toRemoveFlag = true;
         String[] flattedStringArray = getStrings( fieldName );
 
-        Iterator fieldIterator = fieldsToKeep.iterator(); //fieldsToKeep.iterator();
+        Iterator fieldIterator = fieldsToKeep.iterator();
+
+
 
         //goes through a loop of all the fields ( excluding default ) that we want to keep.
         //if the toRemoveFlag is set to false then we want to keep the property, otherwise we set it to true and remove
         //the property.
         while ( fieldIterator.hasNext() ) {
+            //this is the field that we're
             String requiredInclusionString = ( String ) fieldIterator.next();
             String[] flattedRequirementString = getStrings( requiredInclusionString );
 
@@ -172,29 +176,62 @@ public class EntityToMapConverter {
             //Then if that check passes we go to check that both parts are equal. If they are ever not equal
             // e.g one.two.three and one.three.two then it shouldn't be included
             //TODO: regex.
-            for ( int index = 0; index < flattedRequirementString.length; index++ ) {
-                //if the array contains a string that it is equals to then set the remove flag to true
-                //otherwise remain false.
-
-                //one.three
-                //one.two
-                //one
-                if ( flattedStringArray.length <= index ) {
-                    toRemoveFlag = true;
-                    break;
-                }
+            //The regex for this will need to be as follows
+            //Check to make sure that the strings match all the way and end with a period.
+
+            //so if the field we're evaluting against  is in the field name
+            //is one.two.three contains one.two
+            //if one.two is following by nothing or a period then it can be indexed.
+            if(fieldName.length() > requiredInclusionString.length()
+                && fieldName.contains( requiredInclusionString )
+                && fieldName.charAt( requiredInclusionString.length() )=='.' ) {
+                toRemoveFlag = false;
+                break;
+
+                //Since we know that the fieldName cannot be equal to the requiredInclusion criteria due to the if condition before we enter this method
+                //and we are certain that the indexing criteria is shorter we want to be sure that the inclusion criteria
+                //is contained within the field we're evaluating. i.e that one.two.three contains one.two
+
+                //The second part of the if loop also requires that the fieldName is followed by a period after we check to ensure that the
+                //indexing criteria is included in the string. This is done to weed out values such as one.twoexample.three
+                // when we should only keep one.two.three when comparing the indexing criteria of one.two.
+//                if(fieldName.contains( requiredInclusionString ) && fieldName.charAt( requiredInclusionString.length() )=='.'){
+//                    toRemoveFlag = false;
+//                    break;
+//                }
+//                toRemoveFlag = true;
 
-                if ( flattedRequirementString[index].equals( flattedStringArray[index] ) ) {
-                    toRemoveFlag = false;
-                }
-                else {
-                    toRemoveFlag = true;
-                    break;
-                }
             }
-            if ( toRemoveFlag == false ) {
-                break;
+            else {
+                //the of the field we're evaluating is shorter than the indexing criteria so it can't match.
+                //Move onto the next field and see if they match.
+                toRemoveFlag = true;
             }
+
+
+//            for ( int index = 0; index < flattedRequirementString.length; index++ ) {
+//                //if the array contains a string that it is equals to then set the remove flag to true
+//                //otherwise remain false.
+//
+//                //one.three
+//                //one.two
+//                //one
+//                if ( flattedStringArray.length <= index ) {
+//                    toRemoveFlag = true;
+//                    break;
+//                }
+//
+//                if ( flattedRequirementString[index].equals( flattedStringArray[index] ) ) {
+//                    toRemoveFlag = false;
+//                }
+//                else {
+//                    toRemoveFlag = true;
+//                    break;
+//                }
+//            }
+//            if ( toRemoveFlag == false ) {
+//                break;
+//            }
         }
 
         if ( toRemoveFlag ) {