You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/09/28 17:45:45 UTC

[2/3] git commit: Hack to ensure that order by works for String and Number fields.

Hack to ensure that order by works for String and Number fields.


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

Branch: refs/heads/two-dot-o
Commit: 68ee726389200456fb462275c2c603c2c1b5d395
Parents: 16cc4df
Author: Dave Johnson <dm...@apigee.com>
Authored: Sun Sep 28 11:44:55 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Sun Sep 28 11:44:55 2014 -0400

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68ee7263/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 5fb787c..4843854 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
@@ -57,7 +57,10 @@ 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;
@@ -402,18 +405,29 @@ public class EsEntityIndexImpl implements EntityIndex {
             srb = srb.setFrom(0).setSize(query.getLimit());
 
             for (Query.SortPredicate sp : query.getSortPredicates()) {
+
                 final SortOrder order;
                 if (sp.getDirection().equals(Query.SortDirection.ASCENDING)) {
                     order = SortOrder.ASC;
                 } else {
                     order = SortOrder.DESC;
                 }
+
+                String stringFieldName = STRING_PREFIX + sp.getPropertyName(); 
                 FieldSortBuilder sort = SortBuilders
-                    .fieldSort(sp.getPropertyName())
+                    .fieldSort( stringFieldName )
+                    .order(order)
+                    .ignoreUnmapped(true);
+                srb.addSort( sort );
+                log.debug("   Sort: {} order by {}", stringFieldName, order.toString());
+
+                String numberFieldName = NUMBER_PREFIX + sp.getPropertyName(); 
+                sort = SortBuilders
+                    .fieldSort( numberFieldName )
                     .order(order)
                     .ignoreUnmapped(true);
                 srb.addSort( sort );
-                log.debug("   Sort: {} order by {}", sp.getPropertyName(), order.toString());
+                log.debug("   Sort: {} order by {}", numberFieldName, order.toString());
             }
 
             searchResponse = srb.execute().actionGet();
@@ -437,8 +451,6 @@ public class EsEntityIndexImpl implements EntityIndex {
         SearchHits hits = searchResponse.getHits();
         log.debug("   Hit count: {} Total hits: {}", hits.getHits().length, hits.getTotalHits() );
 
-        // TODO: do we always want to fetch entities? When do we fetch refs or ids?
-        // list of entities that will be returned
         List<CandidateResult> candidates = new ArrayList<CandidateResult>();
 
         for (SearchHit hit : hits.getHits()) {