usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [11/35] git commit: Hack to ensure that order by works for String and Number fields.
Date Wed, 01 Oct 2014 14:51:47 GMT
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-rebuildable-index
Commit: 68ee726389200456fb462275c2c603c2c1b5d395
Parents: 16cc4df
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Sun Sep 28 11:44:55 2014 -0400
Committer: Dave Johnson <dmjohnson@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()) {


Mime
View raw message