usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [18/35] git commit: Fix for array querying regression caused by move to new ES field naming schema with prefixes instead of suffixes.
Date Wed, 01 Oct 2014 14:51:54 GMT
Fix for array querying regression caused by move to new ES field naming schema with prefixes
instead of suffixes.


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

Branch: refs/heads/two-dot-o-rebuildable-index
Commit: 009a184df6f7f43e08c6a43fff17e28193821218
Parents: fb050ff
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Mon Sep 29 09:30:22 2014 -0400
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Mon Sep 29 09:30:22 2014 -0400

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 29 +++++++++-----
 .../persistence/index/impl/EsQueryVistor.java   | 42 +++++++++++++-------
 2 files changed, 48 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/009a184d/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 15fadd5..8a1233f 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
@@ -18,6 +18,7 @@
 package org.apache.usergrid.persistence.index.impl;
 
 
+import com.google.common.base.Joiner;
 import com.google.common.util.concurrent.AtomicDouble;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
@@ -57,10 +58,7 @@ import org.apache.usergrid.persistence.model.field.SetField;
 import org.apache.usergrid.persistence.model.field.StringField;
 import org.apache.usergrid.persistence.model.field.UUIDField;
 import org.apache.usergrid.persistence.model.field.value.EntityObject;
-import org.elasticsearch.action.ActionFuture;
 import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
-import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
-import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
@@ -413,20 +411,20 @@ public class EsEntityIndexImpl implements EntityIndex {
                     order = SortOrder.DESC;
                 }
 
-                String stringFieldName = STRING_PREFIX + sp.getPropertyName(); 
-                FieldSortBuilder sort = SortBuilders
+                final String stringFieldName = STRING_PREFIX + sp.getPropertyName(); 
+                final FieldSortBuilder stringSort = SortBuilders
                     .fieldSort( stringFieldName )
                     .order(order)
                     .ignoreUnmapped(true);
-                srb.addSort( sort );
+                srb.addSort( stringSort );
                 log.debug("   Sort: {} order by {}", stringFieldName, order.toString());
 
-                String numberFieldName = NUMBER_PREFIX + sp.getPropertyName(); 
-                sort = SortBuilders
+                final String numberFieldName = NUMBER_PREFIX + sp.getPropertyName(); 
+                final FieldSortBuilder numberSort = SortBuilders
                     .fieldSort( numberFieldName )
                     .order(order)
                     .ignoreUnmapped(true);
-                srb.addSort( sort );
+                srb.addSort( numberSort );
                 log.debug("   Sort: {} order by {}", numberFieldName, order.toString());
             }
 
@@ -490,6 +488,7 @@ public class EsEntityIndexImpl implements EntityIndex {
         Map<String, Object> entityMap = new HashMap<String, Object>();
 
         for (Object f : entity.getFields().toArray()) {
+
             Field field = (Field) f;
 
             if (f instanceof ListField)  {
@@ -497,6 +496,16 @@ public class EsEntityIndexImpl implements EntityIndex {
                 entityMap.put(field.getName().toLowerCase(),
                         new ArrayList(processCollectionForMap(list)));
 
+                if ( !list.isEmpty() ) {
+                    if ( list.get(0) instanceof String ) {
+                        Joiner joiner = Joiner.on(" ").skipNulls();
+                        String joined = joiner.join(list);
+                        entityMap.put( ANALYZED_STRING_PREFIX + field.getName().toLowerCase(),
+                            new ArrayList(processCollectionForMap(list)));
+                        
+                    }
+                }
+
             } else if (f instanceof ArrayField) {
                 List list = (List) field.getValue();
                 entityMap.put(field.getName().toLowerCase(),
@@ -511,6 +520,8 @@ public class EsEntityIndexImpl implements EntityIndex {
                 EntityObject eo = (EntityObject)field.getValue();
                 entityMap.put(field.getName().toLowerCase(), entityToMap(eo)); // recursion
 
+            // Add type information as field-name prefixes
+
             } else if (f instanceof StringField) {
 
                 // index in lower case because Usergrid queries are case insensitive

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/009a184d/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 07f98a2..4f9cd60 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
@@ -150,8 +150,17 @@ public class EsQueryVistor implements QueryVisitor {
         String name = op.getProperty().getValue();
         name = name.toLowerCase();
         Object value = op.getLiteral().getValue();
-        name = addPrefix( value, name, true );
-        stack.push( QueryBuilders.matchQuery( name, value ));
+
+        BoolQueryBuilder qb = QueryBuilders.boolQuery(); // let's do a boolean OR
+        qb.minimumNumberShouldMatch(1); 
+
+        // field is an entity/array that needs no name prefix
+        qb = qb.should( QueryBuilders.matchQuery( name, value ) );
+
+        // OR field is a string and needs the prefix on the name
+        qb = qb.should( QueryBuilders.matchQuery( addPrefix( value.toString(), name, true),
value));
+        
+        stack.push( qb );
     }
 
 
@@ -203,19 +212,24 @@ public class EsQueryVistor implements QueryVisitor {
 
         if ( value instanceof String ) {
             String svalue = (String)value;
-            
-            // use normal prefix, we need unanalyzed field for equals op
-            name = addPrefix( value, name );
 
+            BoolQueryBuilder qb = QueryBuilders.boolQuery();  // let's do a boolean OR
+
+            // field is an entity/array that does not need a prefix on its name
+            qb = qb.should( QueryBuilders.wildcardQuery( name, svalue ) );
+           
+            // or field is just a string that does need a prefix
             if ( svalue.indexOf("*") != -1 ) {
-                stack.push( QueryBuilders.wildcardQuery(name, svalue) );
-                return;
+                qb = qb.should( QueryBuilders.wildcardQuery( addPrefix( value, name ), svalue
) );
+            } else {
+                qb = qb.should( QueryBuilders.termQuery(     addPrefix( value, name ), value
));
             } 
+            stack.push( qb );
+            return;
+        } 
 
-        } else {
-            name = addPrefix( value, name );
-        }
-        stack.push( QueryBuilders.termQuery( name, value ));
+        // assume all other types need prefix
+        stack.push( QueryBuilders.termQuery( addPrefix( value, name ), value ));
     }
 
 
@@ -263,13 +277,13 @@ public class EsQueryVistor implements QueryVisitor {
             name = addStringPrefix( name );
 
         } else if ( value instanceof Number ) {
-            name = addNumberPrefix(name);
+            name = addNumberPrefix( name );
 
         } else if ( value instanceof Boolean ) {
-            name = addBooleanPrefix(name);
+            name = addBooleanPrefix( name );
 
         } else if ( value instanceof UUID ) {
-            name = addStringPrefix(name);
+            name = addStringPrefix( name );
         }
 
         if ( parts.length > 1 ) {


Mime
View raw message