usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [15/33] incubator-usergrid git commit: Fixes paging bug with sub fields
Date Mon, 13 Apr 2015 19:18:22 GMT
Fixes paging bug with sub fields


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

Branch: refs/heads/two-dot-o-dev
Commit: 654e19f66f184f270c32733e5cd99b22f0693c42
Parents: 05c2764
Author: Todd Nine <tnine@apigee.com>
Authored: Wed Apr 8 17:44:40 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Wed Apr 8 17:44:40 2015 -0600

----------------------------------------------------------------------
 .../impl/EsApplicationEntityIndexImpl.java      |  9 +++---
 .../impl/SearchRequestBuilderStrategy.java      | 30 +++++++++++---------
 .../persistence/index/impl/EntityIndexTest.java | 15 +++++-----
 .../persistence/index/impl/GeoPagingTest.java   |  6 ++--
 .../src/test/resources/log4j.properties         |  2 +-
 5 files changed, 35 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/654e19f6/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
index 9db1c26..c5b54c5 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsApplicationEntityIndexImpl.java
@@ -319,16 +319,17 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex
{
 
             //now set this into our map module
             final int minutes = indexFig.getQueryCursorTimeout();
+            //just truncate it, we'll never hit a long value anyway
+
+            final int storageSeconds = ( int ) TimeUnit.MINUTES.toSeconds( minutes );
 
             final QueryState state = new QueryState( query.getOriginalQuery(), limit, esScrollCursor
);
 
             final String queryStateSerialized = state.serialize();
 
-            //just truncate it, we'll never hit a long value anyway
-            mapManager.putString( candidateResults.getCursor(), queryStateSerialized,
-                    ( int ) TimeUnit.MINUTES.toSeconds( minutes ) );
+            mapManager.putString( candidateResults.getCursor(), queryStateSerialized, storageSeconds
);
 
-            logger.debug( " User cursor = {},  Cursor = {} ", candidateResults.getCursor(),
esScrollCursor );
+            logger.debug( " User cursor = {},  Cursor = {} ", cursor, esScrollCursor );
         }
 
         return candidateResults;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/654e19f6/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
index 8c5b1a0..222325e 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/SearchRequestBuilderStrategy.java
@@ -134,6 +134,7 @@ public class SearchRequestBuilderStrategy {
 
             //sort by the entity id if our times are equal
             srb.addSort( SortBuilders.fieldSort( IndexingUtils.ENTITY_ID_FIELDNAME ).order(
SortOrder.ASC ) );
+
             return;
         }
 
@@ -142,7 +143,7 @@ public class SearchRequestBuilderStrategy {
 
         for ( String geoField : geoFields.fields() ) {
 
-            final GeoDistanceSortBuilder geoSort = geoFields.applyOrder(geoField,  SortOrder.ASC);
+            final GeoDistanceSortBuilder geoSort = geoFields.applyOrder( geoField, SortOrder.ASC
);
 
             srb.addSort( geoSort );
         }
@@ -168,25 +169,26 @@ public class SearchRequestBuilderStrategy {
             final String propertyName = sp.getPropertyName();
 
 
-            //if the user specified a geo field in their sort, then honor their sort order
+            //if the user specified a geo field in their sort, then honor their sort order
and use the point they specified
             if ( geoFields.contains( propertyName ) ) {
                 final GeoDistanceSortBuilder geoSort = geoFields.applyOrder(propertyName,
 SortOrder.ASC);
-
                 srb.addSort( geoSort );
             }
 
             //apply regular sort logic, since this is not a geo point
             else {
 
-                srb.addSort( createSort( order, IndexingUtils.FIELD_STRING_NESTED, propertyName
) );
 
+                //sort order is arbitrary if the user changes data types.  Double, long,
string, boolean are supported
+                //default sort types
 
                 srb.addSort( createSort( order, IndexingUtils.FIELD_DOUBLE_NESTED, propertyName
) );
 
-                srb.addSort( createSort( order, IndexingUtils.FIELD_BOOLEAN_NESTED, propertyName
) );
+                srb.addSort( createSort( order, IndexingUtils.FIELD_LONG_NESTED, propertyName
) );
 
+                srb.addSort( createSort( order, IndexingUtils.FIELD_STRING_NESTED, propertyName
) );
 
-                srb.addSort( createSort( order, IndexingUtils.FIELD_LONG_NESTED, propertyName
) );
+                srb.addSort( createSort( order, IndexingUtils.FIELD_BOOLEAN_NESTED, propertyName
) );
             }
         }
     }
@@ -221,14 +223,16 @@ public class SearchRequestBuilderStrategy {
         final String[] sourceTypes = searchTypes.getTypeNames( applicationScope );
 
 
-        final FilterBuilder[] typeTerms = new FilterBuilder[sourceTypes.length];
+        if(sourceTypes.length > 0 ) {
+            final FilterBuilder[] typeTerms = new FilterBuilder[sourceTypes.length];
 
-        for ( int i = 0; i < sourceTypes.length; i++ ) {
-            typeTerms[i] = FilterBuilders.termFilter( IndexingUtils.ENTITY_TYPE_FIELDNAME,
sourceTypes[i] );
-        }
+            for ( int i = 0; i < sourceTypes.length; i++ ) {
+                typeTerms[i] = FilterBuilders.termFilter( IndexingUtils.ENTITY_TYPE_FIELDNAME,
sourceTypes[i] );
+            }
 
-        //add all our types, 1 type must match per query
-        boolQueryFilter.must( FilterBuilders.orFilter( typeTerms ) );
+            //add all our types, 1 type must match per query
+            boolQueryFilter.must( FilterBuilders.orFilter( typeTerms ) );
+        }
 
         //if we have a filter from our visitor, add it
 
@@ -276,7 +280,7 @@ public class SearchRequestBuilderStrategy {
         final TermFilterBuilder propertyFilter = sortPropertyTermFilter( propertyName );
 
 
-        return SortBuilders.fieldSort( fieldName ).order( sortOrder ).ignoreUnmapped( true
)
+        return SortBuilders.fieldSort( fieldName ).order( sortOrder )
                            .setNestedFilter( propertyFilter );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/654e19f6/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 470b934..082b72d 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -665,18 +665,20 @@ public class EntityIndexTest extends BaseIT {
 
         final int size = 10;
 
-        final List<Id> entities = new ArrayList<>( size );
+        final List<Id> entityIds = new ArrayList<>( size );
 
 
         for ( int i = 0; i < size; i++ ) {
 
             final String middleName = "middleName" + UUIDUtils.newTimeUUID();
 
+            final int ordinal = i;
+
             Map entityMap = new HashMap() {{
                 put( "username", "edanuff" );
                 put( "email", "ed@anuff.com" );
                 put( "middlename", middleName );
-                put( "created", System.nanoTime() );
+                put( "ordinal", ordinal );
             }};
 
             final Id userId = new SimpleId( "user" );
@@ -685,9 +687,7 @@ public class EntityIndexTest extends BaseIT {
             EntityUtils.setId( user, userId );
             EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() );
 
-            user.setField( new UUIDField( IndexingUtils.ENTITY_ID_FIELDNAME, UUIDGenerator.newTimeUUID()
) );
-
-            entities.add( userId );
+            entityIds.add( userId );
 
 
             batch.index( indexEdge, user );
@@ -695,6 +695,7 @@ public class EntityIndexTest extends BaseIT {
 
 
         batch.execute().get();
+
         ei.refresh();
 
 
@@ -708,7 +709,7 @@ public class EntityIndexTest extends BaseIT {
 
         for ( int i = 0; i < expectedPages; i++ ) {
             //**
-            final String query = "select * order by created";
+            final String query = "select * order by ordinal asc";
 
             final CandidateResults results =
                     cursor == null ? entityIndex.search( indexEdge, SearchTypes.allTypes(),
query, limit ) :
@@ -723,7 +724,7 @@ public class EntityIndexTest extends BaseIT {
             assertEquals( 1, results.size() );
 
 
-            assertEquals( results.get( 0 ).getId(), entities.get( i ) );
+            assertEquals( results.get( 0 ).getId(), entityIds.get( i ) );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/654e19f6/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoPagingTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoPagingTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoPagingTest.java
index f8ec28e..953e01b 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoPagingTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoPagingTest.java
@@ -103,7 +103,7 @@ public class GeoPagingTest extends BaseIT {
      * Test that geo-query returns co-located entities in expected order.
      */
     @Test
-    public void groupQueriesWithDistanceOrderedResults() throws IOException {
+    public void groupQueriesWithDistanceOrderedResults() throws Exception {
 
         int maxRangeLimit = 9;
         Entity[] cats = new Entity[maxRangeLimit + 1];
@@ -131,10 +131,12 @@ public class GeoPagingTest extends BaseIT {
 
         }
 
-        batch.execute();
+        batch.execute().get();
+
         ei.refresh();
 
 
+
         final String query =  "select * where location within 1500000 of 37, -75" ;
 
         final CandidateResults

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/654e19f6/stack/corepersistence/queryindex/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/resources/log4j.properties b/stack/corepersistence/queryindex/src/test/resources/log4j.properties
index b193f33..5d5f7c2 100644
--- a/stack/corepersistence/queryindex/src/test/resources/log4j.properties
+++ b/stack/corepersistence/queryindex/src/test/resources/log4j.properties
@@ -37,7 +37,7 @@ log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) %c{1} - %m%n
 #log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout
 
 #Debug our queries
-#log4j.logger.org.apache.usergrid.persistence.index.impl.EsApplicationEntityIndexImpl=DEBUG
+log4j.logger.org.apache.usergrid.persistence.index.impl.EsApplicationEntityIndexImpl=DEBUG
 #Debug our writes
 #log4j.logger.org.apache.usergrid.persistence.index.impl.EsIndexBufferConsumerImpl=DEBUG
 #Batch debugging


Mime
View raw message