You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/03/31 23:00:56 UTC
[18/50] incubator-usergrid git commit: change query to support legacy
context
change query to support legacy context
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/90832ca0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/90832ca0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/90832ca0
Branch: refs/heads/USERGRID-473
Commit: 90832ca0ccab39c6d170d7d42eae3314468f5d17
Parents: e0a79db
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Mar 24 16:18:56 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Mar 24 16:18:56 2015 -0600
----------------------------------------------------------------------
.../persistence/index/impl/EntityToMapConverter.java | 8 ++++++--
.../index/impl/EsApplicationEntityIndexImpl.java | 3 ++-
.../usergrid/persistence/index/impl/IndexRequest.java | 4 +---
.../usergrid/persistence/index/impl/IndexingUtils.java | 8 +++++++-
.../apache/usergrid/persistence/index/query/Query.java | 13 +++++++++----
.../persistence/query/tree/GrammarTreeTest.java | 4 ++--
6 files changed, 27 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90832ca0/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 6e72159..fdd9b92 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
@@ -16,6 +16,7 @@
*/
package org.apache.usergrid.persistence.index.impl;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.field.*;
import org.apache.usergrid.persistence.model.field.value.EntityObject;
@@ -35,7 +36,7 @@ public class EntityToMapConverter {
* @param entity The entity
* @param context The context this entity appears in
*/
- public static Map convert( final Entity entity, final String context ) {
+ public static Map convert(ApplicationScope applicationScope, final Entity entity, final String context ) {
final Map entityMap = entityToMap( entity );
//add the context for filtering later
@@ -43,7 +44,10 @@ public class EntityToMapConverter {
//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( ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase());
+ entityMap.put( ENTITYID_ID_FIELDNAME, IndexingUtils.idString(entity.getId()).toLowerCase() );
+
+ entityMap.put( APPLICATION_ID_FIELDNAME, idString(applicationScope.getApplication()) );
+
return entityMap;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90832ca0/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 1debe3b..ade2286 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
@@ -145,10 +145,11 @@ public class EsApplicationEntityIndexImpl implements ApplicationEntityIndex{
SearchResponse searchResponse;
if ( query.getCursor() == null ) {
+ String[] contexts = new String[]{createContextName(applicationScope, indexScope),createLegacyContextName(applicationScope,indexScope)};
SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias() )
.setTypes(searchTypes.getTypeNames(applicationScope))
.setScroll(cursorTimeout + "m")
- .setQuery(query.createQueryBuilder(createContextName(applicationScope, indexScope)));
+ .setQuery(query.createQueryBuilder(contexts));
final FilterBuilder fb = query.createFilterBuilder();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90832ca0/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
index 9eae481..dc05820 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexRequest.java
@@ -55,16 +55,14 @@ public class IndexRequest implements BatchRequest {
}
public IndexRequest( final String writeAlias, final ApplicationScope applicationScope, String context , Entity entity) {
- this(writeAlias, applicationScope, SearchType.fromId(entity.getId()),IndexingUtils.createIndexDocId(entity,context), EntityToMapConverter.convert(entity, context));
+ this(writeAlias, applicationScope, SearchType.fromId(entity.getId()),IndexingUtils.createIndexDocId(entity,context), EntityToMapConverter.convert(applicationScope,entity, context));
}
public IndexRequest( final String writeAlias, final ApplicationScope applicationScope,SearchType searchType, String documentId, Map<String, Object> data) {
- data.put(APPLICATION_ID_FIELDNAME, idString(applicationScope.getApplication()));
this.writeAlias = writeAlias;
this.entityType = searchType.getTypeName(applicationScope);
this.data = data;
this.documentId = documentId;
-
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90832ca0/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
index 2fb56d1..0330bbf 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
@@ -76,7 +76,13 @@ public class IndexingUtils {
sb.append( scope.getName() );
return sb.toString();
}
-
+ public static String createLegacyContextName(ApplicationScope applicationScope, IndexScope scope ) {
+ StringBuilder sb = new StringBuilder();
+ idString(sb, scope.getOwner());
+ sb.append( SEPARATOR );
+ sb.append( scope.getName() );
+ return sb.toString();
+ }
/**
* Append the id to the string
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90832ca0/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
index 67a1731..438d82e 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
@@ -60,6 +60,7 @@ import org.apache.usergrid.persistence.index.utils.ClassUtils;
import org.apache.usergrid.persistence.index.utils.ConversionUtils;
import org.apache.usergrid.persistence.index.utils.ListUtils;
import org.apache.usergrid.persistence.index.utils.MapUtils;
+import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.FilterBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
@@ -147,7 +148,7 @@ public class Query {
}
- public QueryBuilder createQueryBuilder( final String context ) {
+ public QueryBuilder createQueryBuilder( final String[] contexts ) {
QueryBuilder queryBuilder = null;
@@ -178,14 +179,18 @@ public class Query {
// TODO evaluate performance when it's an all query.
// Do we need to put the context term first for performance?
+ BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
+ for(String context : contexts){
+ boolQueryBuilder = boolQueryBuilder.should(QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context ));
+ }
+ boolQueryBuilder = boolQueryBuilder.minimumNumberShouldMatch(1);
if ( queryBuilder != null ) {
- queryBuilder = QueryBuilders.boolQuery().must( queryBuilder ).must( QueryBuilders
- .termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context ) );
+ queryBuilder = boolQueryBuilder.must( queryBuilder );
}
//nothing was specified ensure we specify the context in the search
else {
- queryBuilder = QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context );
+ queryBuilder = boolQueryBuilder;
}
return queryBuilder;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90832ca0/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
index 34185b3..102e222 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/GrammarTreeTest.java
@@ -411,7 +411,7 @@ public class GrammarTreeTest {
@Test
public void selectGeoWithAnd() throws RecognitionException {
String queryString = "select * where location within 20000 of 37,-75 "
- + "and created > 1407776999925 and created < 1407777000266";
+ + "and created > 1407776999925 and created < 1407777000266";
ANTLRStringStream in = new ANTLRStringStream( queryString );
CpQueryFilterLexer lexer = new CpQueryFilterLexer( in );
@@ -429,7 +429,7 @@ public class GrammarTreeTest {
assertEquals( 37f, withinOperand.getLatitude().getFloatValue(), 0 );
assertEquals( -75f, withinOperand.getLongitude().getFloatValue(), 0 );
- QueryBuilder qb = query.createQueryBuilder("testcontext");
+ QueryBuilder qb = query.createQueryBuilder(new String[]{"testcontext"});
}