Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Fixes paging bug with sub fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd Nine committed Apr 8, 2015
1 parent 05c2764 commit 654e19f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
Expand Up @@ -319,16 +319,17 @@ private CandidateResults parseResults( final SearchResponse searchResponse, fina


//now set this into our map module //now set this into our map module
final int minutes = indexFig.getQueryCursorTimeout(); 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 QueryState state = new QueryState( query.getOriginalQuery(), limit, esScrollCursor );


final String queryStateSerialized = state.serialize(); final String queryStateSerialized = state.serialize();


//just truncate it, we'll never hit a long value anyway mapManager.putString( candidateResults.getCursor(), queryStateSerialized, storageSeconds );
mapManager.putString( candidateResults.getCursor(), queryStateSerialized,
( int ) TimeUnit.MINUTES.toSeconds( minutes ) );


logger.debug( " User cursor = {}, Cursor = {} ", candidateResults.getCursor(), esScrollCursor ); logger.debug( " User cursor = {}, Cursor = {} ", cursor, esScrollCursor );
} }


return candidateResults; return candidateResults;
Expand Down
Expand Up @@ -134,6 +134,7 @@ private void applyDefaultSortPredicates( final SearchRequestBuilder srb, final G


//sort by the entity id if our times are equal //sort by the entity id if our times are equal
srb.addSort( SortBuilders.fieldSort( IndexingUtils.ENTITY_ID_FIELDNAME ).order( SortOrder.ASC ) ); srb.addSort( SortBuilders.fieldSort( IndexingUtils.ENTITY_ID_FIELDNAME ).order( SortOrder.ASC ) );

return; return;
} }


Expand All @@ -142,7 +143,7 @@ private void applyDefaultSortPredicates( final SearchRequestBuilder srb, final G


for ( String geoField : geoFields.fields() ) { for ( String geoField : geoFields.fields() ) {


final GeoDistanceSortBuilder geoSort = geoFields.applyOrder(geoField, SortOrder.ASC); final GeoDistanceSortBuilder geoSort = geoFields.applyOrder( geoField, SortOrder.ASC );


srb.addSort( geoSort ); srb.addSort( geoSort );
} }
Expand All @@ -168,25 +169,26 @@ private void applySortPredicates( final SearchRequestBuilder srb, final ParsedQu
final String propertyName = sp.getPropertyName(); 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 ) ) { if ( geoFields.contains( propertyName ) ) {
final GeoDistanceSortBuilder geoSort = geoFields.applyOrder(propertyName, SortOrder.ASC); final GeoDistanceSortBuilder geoSort = geoFields.applyOrder(propertyName, SortOrder.ASC);

srb.addSort( geoSort ); srb.addSort( geoSort );
} }


//apply regular sort logic, since this is not a geo point //apply regular sort logic, since this is not a geo point
else { 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_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 ) );
} }
} }
} }
Expand Down Expand Up @@ -221,14 +223,16 @@ private FilterBuilder createFilterBuilder( final SearchEdge searchEdge, final Qu
final String[] sourceTypes = searchTypes.getTypeNames( applicationScope ); 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++ ) { for ( int i = 0; i < sourceTypes.length; i++ ) {
typeTerms[i] = FilterBuilders.termFilter( IndexingUtils.ENTITY_TYPE_FIELDNAME, sourceTypes[i] ); typeTerms[i] = FilterBuilders.termFilter( IndexingUtils.ENTITY_TYPE_FIELDNAME, sourceTypes[i] );
} }


//add all our types, 1 type must match per query //add all our types, 1 type must match per query
boolQueryFilter.must( FilterBuilders.orFilter( typeTerms ) ); boolQueryFilter.must( FilterBuilders.orFilter( typeTerms ) );
}


//if we have a filter from our visitor, add it //if we have a filter from our visitor, add it


Expand Down Expand Up @@ -276,7 +280,7 @@ private FieldSortBuilder createSort( final SortOrder sortOrder, final String fie
final TermFilterBuilder propertyFilter = sortPropertyTermFilter( propertyName ); final TermFilterBuilder propertyFilter = sortPropertyTermFilter( propertyName );




return SortBuilders.fieldSort( fieldName ).order( sortOrder ).ignoreUnmapped( true ) return SortBuilders.fieldSort( fieldName ).order( sortOrder )
.setNestedFilter( propertyFilter ); .setNestedFilter( propertyFilter );
} }
} }
Expand Up @@ -665,18 +665,20 @@ public void testCursorFormat() throws Exception {


final int size = 10; 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++ ) { for ( int i = 0; i < size; i++ ) {


final String middleName = "middleName" + UUIDUtils.newTimeUUID(); final String middleName = "middleName" + UUIDUtils.newTimeUUID();


final int ordinal = i;

Map entityMap = new HashMap() {{ Map entityMap = new HashMap() {{
put( "username", "edanuff" ); put( "username", "edanuff" );
put( "email", "ed@anuff.com" ); put( "email", "ed@anuff.com" );
put( "middlename", middleName ); put( "middlename", middleName );
put( "created", System.nanoTime() ); put( "ordinal", ordinal );
}}; }};


final Id userId = new SimpleId( "user" ); final Id userId = new SimpleId( "user" );
Expand All @@ -685,16 +687,15 @@ public void testCursorFormat() throws Exception {
EntityUtils.setId( user, userId ); EntityUtils.setId( user, userId );
EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() ); EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() );


user.setField( new UUIDField( IndexingUtils.ENTITY_ID_FIELDNAME, UUIDGenerator.newTimeUUID() ) ); entityIds.add( userId );

entities.add( userId );




batch.index( indexEdge, user ); batch.index( indexEdge, user );
} }




batch.execute().get(); batch.execute().get();

ei.refresh(); ei.refresh();




Expand All @@ -708,7 +709,7 @@ public void testCursorFormat() throws Exception {


for ( int i = 0; i < expectedPages; i++ ) { 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 = final CandidateResults results =
cursor == null ? entityIndex.search( indexEdge, SearchTypes.allTypes(), query, limit ) : cursor == null ? entityIndex.search( indexEdge, SearchTypes.allTypes(), query, limit ) :
Expand All @@ -723,7 +724,7 @@ public void testCursorFormat() throws Exception {
assertEquals( 1, results.size() ); assertEquals( 1, results.size() );




assertEquals( results.get( 0 ).getId(), entities.get( i ) ); assertEquals( results.get( 0 ).getId(), entityIds.get( i ) );
} }
} }


Expand Down
Expand Up @@ -103,7 +103,7 @@ public void setup() {
* Test that geo-query returns co-located entities in expected order. * Test that geo-query returns co-located entities in expected order.
*/ */
@Test @Test
public void groupQueriesWithDistanceOrderedResults() throws IOException { public void groupQueriesWithDistanceOrderedResults() throws Exception {


int maxRangeLimit = 9; int maxRangeLimit = 9;
Entity[] cats = new Entity[maxRangeLimit + 1]; Entity[] cats = new Entity[maxRangeLimit + 1];
Expand Down Expand Up @@ -131,10 +131,12 @@ public void groupQueriesWithDistanceOrderedResults() throws IOException {


} }


batch.execute(); batch.execute().get();

ei.refresh(); ei.refresh();





final String query = "select * where location within 1500000 of 37, -75" ; final String query = "select * where location within 1500000 of 37, -75" ;


final CandidateResults final CandidateResults
Expand Down
Expand Up @@ -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 #log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout


#Debug our queries #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 #Debug our writes
#log4j.logger.org.apache.usergrid.persistence.index.impl.EsIndexBufferConsumerImpl=DEBUG #log4j.logger.org.apache.usergrid.persistence.index.impl.EsIndexBufferConsumerImpl=DEBUG
#Batch debugging #Batch debugging
Expand Down

0 comments on commit 654e19f

Please sign in to comment.