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: Search requests are no working with types and scopes.
Date Mon, 06 Apr 2015 22:23:33 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-536 cb9b06a38 -> 8f70c7c29


Search requests are no working with types and scopes.


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

Branch: refs/heads/USERGRID-536
Commit: 8f70c7c29e62f692c0852a6c21062eca52ec86a5
Parents: cb9b06a
Author: Todd Nine <tnine@apigee.com>
Authored: Mon Apr 6 16:23:32 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Mon Apr 6 16:23:32 2015 -0600

----------------------------------------------------------------------
 .../persistence/index/impl/EsQueryVistor.java   | 60 ++++++++++++--------
 .../persistence/index/impl/IndexRequest.java    |  4 +-
 .../persistence/index/impl/IndexingUtils.java   |  2 +-
 .../impl/SearchRequestBuilderStrategy.java      | 56 +++++++++++-------
 .../index/query/tree/QueryVisitor.java          | 22 ++++++-
 .../index/impl/BufferQueueSQSImplTest.java      |  4 +-
 .../src/test/resources/log4j.properties         |  5 +-
 7 files changed, 100 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f70c7c2/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
index 39b101b..2e2509a 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
@@ -20,10 +20,14 @@ package org.apache.usergrid.persistence.index.impl;
 
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Stack;
 import java.util.UUID;
 
+import javax.swing.text.html.Option;
+
 import org.elasticsearch.common.unit.DistanceUnit;
 import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.FilterBuilder;
@@ -49,8 +53,7 @@ import org.apache.usergrid.persistence.index.query.tree.QueryVisitor;
 import org.apache.usergrid.persistence.index.query.tree.WithinOperand;
 
 import com.google.common.base.Joiner;
-
-import static org.apache.usergrid.persistence.index.impl.IndexingUtils.*;
+import com.google.common.base.Optional;
 
 
 /**
@@ -332,31 +335,40 @@ public class EsQueryVistor implements QueryVisitor {
 
 
     @Override
-    public QueryBuilder getQueryBuilder() {
-        if ( stack.isEmpty() ) {
-            return null;
-        }
-        return stack.pop();
+    public Optional<QueryBuilder> getQueryBuilder() {
+//        if ( stack.isEmpty() ) {
+            return Optional.absent();
+//        }
+//        return stack.pop();
+
+
     }
 
 
     @Override
-	public FilterBuilder getFilterBuilder() {
-
-		if ( filterBuilders.size() >  1 ) {
-
-			FilterBuilder andFilter = null;
-			for ( FilterBuilder fb : filterBuilders ) {
-				if ( andFilter == null ) {
-					andFilter = FilterBuilders.andFilter( fb );
-				} else {
-					andFilter = FilterBuilders.andFilter( andFilter, fb );
-				}
-			}
-
-		} else if ( !filterBuilders.isEmpty() ) {
-			return filterBuilders.get(0);
-		}
-		return null;
+	public Optional<FilterBuilder> getFilterBuilder() {
+        return Optional.absent();
+//
+//		if ( filterBuilders.size() >  1 ) {
+//
+//			FilterBuilder andFilter = null;
+//			for ( FilterBuilder fb : filterBuilders ) {
+//				if ( andFilter == null ) {
+//					andFilter = FilterBuilders.andFilter( fb );
+//				} else {
+//					andFilter = FilterBuilders.andFilter( andFilter, fb );
+//				}
+//			}
+//
+//		} else if ( !filterBuilders.isEmpty() ) {
+//			return filterBuilders.get(0);
+//		}
+//		return null;
 	}
+
+
+    @Override
+    public Collection<String> getGeoSelectFields() {
+        return Collections.EMPTY_LIST;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f70c7c2/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 8894197..a2a1c4d 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
@@ -50,11 +50,11 @@ public class IndexRequest implements BatchRequest {
     public Map<String, Object> data;
 
     public IndexRequest( final String writeAlias, final ApplicationScope applicationScope,
IndexEdge indexEdge, Entity entity) {
-        this(writeAlias, applicationScope, SearchType.fromId( entity.getId() ),IndexingUtils.createIndexDocId(applicationScope,
entity,indexEdge), EntityToMapConverter.convert(applicationScope,indexEdge, entity));
+        this(writeAlias,IndexingUtils.createIndexDocId(applicationScope, entity,indexEdge),
EntityToMapConverter.convert(applicationScope,indexEdge, entity));
 
     }
 
-    public IndexRequest( final String writeAlias, final ApplicationScope applicationScope,
SearchType searchType, String documentId,  Map<String, Object> data) {
+    public IndexRequest( final String writeAlias, String documentId,  Map<String, Object>
data) {
         this.writeAlias = writeAlias;
         this.data = data;
         this.documentId = documentId;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f70c7c2/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 299b95b..de1bfd9 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
@@ -146,7 +146,7 @@ public class IndexingUtils {
                                            final UUID version, final SearchEdge searchEdge
) {
 
         StringBuilder sb = new StringBuilder();
-        idString( applicationScope.getApplication() );
+        idString( sb, applicationScope.getApplication() );
         sb.append( FIELD_SEPERATOR );
         idString( sb, entityId );
         sb.append( FIELD_SEPERATOR );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f70c7c2/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 1e0ecde..fa82ad6 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
@@ -42,6 +42,7 @@ import org.apache.usergrid.persistence.index.query.ParsedQuery;
 import org.apache.usergrid.persistence.index.query.SortPredicate;
 import org.apache.usergrid.persistence.index.query.tree.QueryVisitor;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createContextName;
@@ -77,18 +78,22 @@ public class SearchRequestBuilderStrategy {
         Preconditions
                 .checkArgument( limit <= EntityIndex.MAX_LIMIT, "limit is greater than
max " + EntityIndex.MAX_LIMIT );
 
-        SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias()
)
-                                             .setTypes( searchTypes.getTypeNames( applicationScope
) )
-                                             .setScroll( cursorTimeout + "m" );
+        SearchRequestBuilder srb =
+                esProvider.getClient().prepareSearch( alias.getReadAlias() ).setTypes( IndexingUtils.ES_ENTITY_TYPE
)
+                          .setScroll( cursorTimeout + "m" );
 
+        //TODO, make this work
+        //        searchTypes.getTypeNames( applicationScope )
 
-        final QueryVisitor visitor = visitParsedQuery(query);
+        final QueryVisitor visitor = visitParsedQuery( query );
 
-        srb.setQuery(  createQueryBuilder( searchEdge, visitor ) );
+        srb.setQuery( createQueryBuilder( searchEdge, visitor, searchTypes ) );
 
-        final FilterBuilder fb = visitor.getFilterBuilder();
+        final Optional<FilterBuilder> fb = visitor.getFilterBuilder();
 
-        srb.setPostFilter( fb );
+        if ( fb.isPresent() ) {
+            srb.setPostFilter( fb.get() );
+        }
 
 
         srb = srb.setFrom( 0 ).setSize( limit );
@@ -128,18 +133,15 @@ public class SearchRequestBuilderStrategy {
             srb.addSort( createSort( order, IndexingUtils.SORT_FIELD_LONG, propertyName )
);
 
             srb.addSort( createSort( order, IndexingUtils.SORT_FIELD_FLOAT, propertyName
) );
-
-
         }
         return srb;
     }
 
 
-    public QueryBuilder createQueryBuilder( final SearchEdge searchEdge, final QueryVisitor
visitor ) {
+    public QueryBuilder createQueryBuilder( final SearchEdge searchEdge, final QueryVisitor
visitor,
+                                            final SearchTypes searchTypes ) {
         String context = createContextName( applicationScope, searchEdge );
 
-        QueryBuilder queryBuilder = visitor.getQueryBuilder();
-
 
         // Add our filter for context to our query for fast execution.
         // Fast because it utilizes bitsets internally. See this post for more detail.
@@ -153,20 +155,32 @@ public class SearchRequestBuilderStrategy {
 
         boolQueryBuilder.must( QueryBuilders.termQuery( IndexingUtils.EDGE_SEARCH_FIELDNAME,
context ) );
 
-        boolQueryBuilder.must( queryBuilder );
 
-        return queryBuilder;
-    }
+        /**
+         * Get the scopes and add them
+         */
+
 
+        final String[] sourceTypes = searchTypes.getTypeNames( applicationScope );
 
+        //add all our types, 1 type must match per query
+        boolQueryBuilder.must( QueryBuilders.termsQuery( IndexingUtils.ENTITY_TYPE_FIELDNAME,
sourceTypes )
+                                            .minimumMatch( 1 ) );
+
+        Optional<QueryBuilder> queryBuilder = visitor.getQueryBuilder();
+
+        if ( queryBuilder.isPresent() ) {
+            boolQueryBuilder.must( queryBuilder.get() );
+        }
+
+        return boolQueryBuilder;
+    }
 
 
     /**
      * Perform our visit of the query once for efficiency
-     * @param parsedQuery
-     * @return
      */
-    private QueryVisitor visitParsedQuery(final ParsedQuery parsedQuery){
+    private QueryVisitor visitParsedQuery( final ParsedQuery parsedQuery ) {
         QueryVisitor v = new EsQueryVistor();
 
         if ( parsedQuery.getRootOperand() != null ) {
@@ -177,7 +191,6 @@ public class SearchRequestBuilderStrategy {
             catch ( IndexException ex ) {
                 throw new RuntimeException( "Error building ElasticSearch query", ex );
             }
-
         }
 
         return v;
@@ -186,10 +199,10 @@ public class SearchRequestBuilderStrategy {
 
     /**
      * Create a sort for the property name and field name specified
+     *
      * @param sortOrder The sort order
      * @param fieldName The name of the field for the type
      * @param propertyName The property name the user specified for the sort
-     * @return
      */
     private FieldSortBuilder createSort( final SortOrder sortOrder, final String fieldName,
                                          final String propertyName ) {
@@ -197,6 +210,7 @@ public class SearchRequestBuilderStrategy {
         final TermFilterBuilder propertyFilter = FilterBuilders.termFilter( IndexingUtils.FIELD_NAME,
propertyName );
 
 
-        return SortBuilders.fieldSort( fieldName ).order( sortOrder ).ignoreUnmapped( true
).setNestedFilter( propertyFilter );
+        return SortBuilders.fieldSort( fieldName ).order( sortOrder ).ignoreUnmapped( true
)
+                           .setNestedFilter( propertyFilter );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f70c7c2/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
index 5fc1304..42d6d3a 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
@@ -19,12 +19,18 @@
 package org.apache.usergrid.persistence.index.query.tree;
 
 
+import java.util.Collection;
+
 import org.apache.usergrid.persistence.index.exceptions.NoFullTextIndexException;
 import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
 import org.apache.usergrid.persistence.index.exceptions.IndexException;
+import org.apache.usergrid.persistence.index.query.SortPredicate;
+
 import org.elasticsearch.index.query.FilterBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 
+import com.google.common.base.Optional;
+
 
 /**
  * Interface for visiting nodes in our AST as we produce
@@ -96,8 +102,20 @@ public interface QueryVisitor {
     /** 
      * Returns resulting query builder.
      */
-    QueryBuilder getQueryBuilder();
+    Optional<QueryBuilder> getQueryBuilder();
+
 
+    /**
+     * Return any filters created during parsing
+     * @return
+     */
+	Optional<FilterBuilder> getFilterBuilder();
 
-	FilterBuilder getFilterBuilder();
+    /**
+     * Some searches, such as geo have a side effect of adding a geo sort.  Get any sorts
that are side effects
+     * of the query terms, in the order they should be applied.  Note that user specified
sort orders will trump
+     * these sorts
+     * @return
+     */
+    Collection<String> getGeoSelectFields();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f70c7c2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
index 12be269..43e581a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/BufferQueueSQSImplTest.java
@@ -97,11 +97,11 @@ public class BufferQueueSQSImplTest {
         assumeTrue( ugProvider.getCredentials().getAWSSecretKey() != null );
 
         final Map<String, Object> request1Data  = new HashMap<String, Object>()
{{put("test", "testval1");}};
-        final IndexRequest indexRequest1 =  new IndexRequest( "testAlias1", applicationScope,
SearchType.fromType("testType1"), "testDoc1",request1Data );
+        final IndexRequest indexRequest1 =  new IndexRequest( "testAlias1", "testDoc1",request1Data
);
 
 
         final Map<String, Object> request2Data  = new HashMap<String, Object>()
{{put("test", "testval2");}};
-        final IndexRequest indexRequest2 =  new IndexRequest( "testAlias2", applicationScope,
SearchType.fromType( "testType2"), "testDoc2",request2Data );
+        final IndexRequest indexRequest2 =  new IndexRequest( "testAlias2", "testDoc2",request2Data
);
 
 
         //de-index request

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f70c7c2/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 a13ce23..1dc4831 100644
--- a/stack/corepersistence/queryindex/src/test/resources/log4j.properties
+++ b/stack/corepersistence/queryindex/src/test/resources/log4j.properties
@@ -26,7 +26,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) %c{1} - %m%n
 
-log4j.logger.org.apache.usergrid=INFO
+
 
 #log4j.logger.org.apache.usergrid.persistence.index=DEBUG
 #log4j.logger.org.apache.usergrid.persistence.index.impl=DEBUG
@@ -35,3 +35,6 @@ log4j.logger.org.apache.usergrid=INFO
 #log4j.logger.org.apache.usergrid.persistence.index.utils=DEBUG
 
 #log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout
+
+log4j.logger.org.apache.usergrid.persistence.index.impl.EsApplicationEntityIndexImpl=DEBUG
+log4j.logger.org.apache.usergrid=INFO


Mime
View raw message