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/10/01 16:52:01 UTC

[25/35] git commit: Need to support order by boolean too.

Need to support order by boolean too.


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

Branch: refs/heads/two-dot-o-rebuildable-index
Commit: 2ea3ee1adde4275e32167d84e3076bfdf7b3f7ad
Parents: a05ed4e
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Sep 29 14:50:16 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Sep 29 14:50:16 2014 -0400

----------------------------------------------------------------------
 .../persistence/index/impl/EsEntityIndexImpl.java      | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ea3ee1a/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 8a1233f..8401e13 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
@@ -411,6 +411,11 @@ public class EsEntityIndexImpl implements EntityIndex {
                     order = SortOrder.DESC;
                 }
 
+                // we do not know the type of the "order by" property and so we do not know what
+                // type prefix to use. So, here we add an order by clause for every possible type 
+                // that you can order by: string, number and boolean and we ask ElasticSearch 
+                // to ignore any fields that are not present.
+
                 final String stringFieldName = STRING_PREFIX + sp.getPropertyName(); 
                 final FieldSortBuilder stringSort = SortBuilders
                     .fieldSort( stringFieldName )
@@ -426,6 +431,14 @@ public class EsEntityIndexImpl implements EntityIndex {
                     .ignoreUnmapped(true);
                 srb.addSort( numberSort );
                 log.debug("   Sort: {} order by {}", numberFieldName, order.toString());
+
+                final String booleanFieldName = BOOLEAN_PREFIX + sp.getPropertyName(); 
+                final FieldSortBuilder booleanSort = SortBuilders
+                        .fieldSort( booleanFieldName )
+                        .order(order)
+                        .ignoreUnmapped(true);
+                srb.addSort( booleanSort );
+                log.debug("   Sort: {} order by {}", booleanFieldName, order.toString());
             }
 
             searchResponse = srb.execute().actionGet();