usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject incubator-usergrid git commit: Finished updating search by versions. Removed query use to be more declarative.
Date Fri, 07 Nov 2014 05:03:02 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/es-type-updates ef77a5a4e -> 1debf19b3


Finished updating search by versions.  Removed query use to be more declarative.


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

Branch: refs/heads/es-type-updates
Commit: 1debf19b30510b3f9f4abe57d8cba88efaec9208
Parents: ef77a5a
Author: Todd Nine <tnine@apigee.com>
Authored: Thu Nov 6 22:02:49 2014 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Thu Nov 6 22:02:49 2014 -0700

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexBatchImpl.java      |  2 +-
 .../index/impl/EsEntityIndexImpl.java           | 69 ++++++++++++++------
 .../persistence/index/impl/EntityIndexTest.java |  9 ---
 3 files changed, 49 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1debf19b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 01f22c0..e6920f5 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -259,7 +259,7 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
         //but the fieldname
         //we have to prefix because we use query equality to seek this later.  TODO see if
we can make this more declarative
-        entityMap.put( STRING_PREFIX+ ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase()
);
+        entityMap.put( ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase()
);
 
         return entityMap;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1debf19b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index d7955c4..cb56c7d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -232,28 +232,21 @@ public class EsEntityIndexImpl implements EntityIndex {
         final String context = IndexingUtils.createContextName( indexScope );
         final String[] entityTypes = searchTypes.getTypeNames();
 
-        QueryBuilder qb = query.createQueryBuilder(context);
+        QueryBuilder qb = query.createQueryBuilder( context );
 
 
         SearchResponse searchResponse;
 
         if ( query.getCursor() == null ) {
             SearchRequestBuilder srb = esProvider.getClient().prepareSearch( indexName ).setTypes(
entityTypes )
-                                                 .setScroll( cursorTimeout + "m" ).setQuery(
qb );;
-
-
-            //we must add a "must" operation to our entity context.
-
-
-            //set our final query
+                                                 .setScroll( cursorTimeout + "m" ).setQuery(
qb );
 
 
             if ( logger.isDebugEnabled() ) {
-                        logger.debug( "Searching index {}\n  scope{} \n type {}\n   query
{} limit {}", new Object[] {
-                                this.indexName, context, entityTypes, qb.toString().replace(
"\n", " " ), query.getLimit()
-                        } );
-                    }
-
+                logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} limit
{}", new Object[] {
+                        this.indexName, context, entityTypes, qb.toString().replace( "\n",
" " ), query.getLimit()
+                } );
+            }
 
 
             final FilterBuilder fb = query.createFilterBuilder();
@@ -287,6 +280,7 @@ public class EsEntityIndexImpl implements EntityIndex {
                 final FieldSortBuilder stringSort =
                         SortBuilders.fieldSort( stringFieldName ).order( order ).ignoreUnmapped(
true );
                 srb.addSort( stringSort );
+
                 logger.debug( "   Sort: {} order by {}", stringFieldName, order.toString()
);
 
                 final String numberFieldName = NUMBER_PREFIX + sp.getPropertyName();
@@ -340,12 +334,21 @@ public class EsEntityIndexImpl implements EntityIndex {
             failureMonitor.success();
         }
 
-        SearchHits hits = searchResponse.getHits();
-        logger.debug( "   Hit count: {} Total hits: {}", hits.getHits().length, hits.getTotalHits()
);
+        return parseResults( searchResponse, query );
+    }
+
+
+    private CandidateResults parseResults( final SearchResponse searchResponse, final Query
query ) {
 
-        List<CandidateResult> candidates = new ArrayList<CandidateResult>();
+        final SearchHits searchHits = searchResponse.getHits();
+        final SearchHit[] hits = searchHits.getHits();
+        final int length = hits.length;
 
-        for ( SearchHit hit : hits.getHits() ) {
+        logger.debug( "   Hit count: {} Total hits: {}", length, searchHits.getTotalHits()
);
+
+        List<CandidateResult> candidates = new ArrayList<>( length );
+
+        for ( SearchHit hit : hits ) {
 
             String[] idparts = hit.getId().split( SPLITTER );
             String id = idparts[0];
@@ -396,10 +399,34 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     @Override
     public CandidateResults getEntityVersions( final IndexScope scope, final Id id ) {
-        Query query = new Query();
-        query.addEqualityFilter( ENTITYID_ID_FIELDNAME, IndexingUtils.idString( id ).toLowerCase()
);
-        CandidateResults results = search( scope, SearchTypes.fromTypes( id.getType() ),
query );
-        return results;
+
+        //since we don't have paging inputs, there's no point in executing a query for paging.
+
+        final String context = IndexingUtils.createContextName( scope );
+        final SearchTypes searchTypes = SearchTypes.fromTypes( id.getType() );
+
+        final QueryBuilder queryBuilder = QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME,
context );
+
+
+        final SearchRequestBuilder srb =
+                esProvider.getClient().prepareSearch( indexName ).setTypes( searchTypes.getTypeNames()
)
+                          .setScroll( cursorTimeout + "m" ).setQuery( queryBuilder );
+
+
+        final SearchResponse searchResponse;
+        try {
+            searchResponse = srb.execute().actionGet();
+        }
+        catch ( Throwable t ) {
+            logger.error( "Unable to communicate with elasticsearch" );
+            failureMonitor.fail( "Unable to execute batch", t );
+            throw t;
+        }
+
+
+        failureMonitor.success();
+
+        return parseResults( searchResponse, new Query(  ) );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1debf19b/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 a1240f1..72058ff 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
@@ -72,15 +72,6 @@ public class EntityIndexTest extends BaseIT {
 
     private static final Logger log = LoggerFactory.getLogger( EntityIndexTest.class );
 
-    @ClassRule
-    public static CassandraRule cass = new CassandraRule();
-
-    @Rule
-    public ElasticSearchResource elasticSearchResource = new ElasticSearchResource();
-
-    @Inject
-    @Rule
-    public MigrationManagerRule migrationManagerRule;
 
     @Inject
     public EntityIndexFactory eif;


Mime
View raw message