add distance field
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/5cc0b380 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/5cc0b380 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/5cc0b380 Branch: refs/heads/master Commit: 5cc0b38072654546c292f3f78843e319924e99f4 Parents: a9da97d Author: Shawn Feldman <sfeld...@apache.org> Authored: Fri Nov 6 11:14:28 2015 -0700 Committer: Shawn Feldman <sfeld...@apache.org> Committed: Fri Nov 6 11:14:28 2015 -0700 ---------------------------------------------------------------------- .../usergrid/persistence/model/entity/EntityToMapConverter.java | 1 + .../apache/usergrid/persistence/model/field/DistanceField.java | 2 +- .../apache/usergrid/persistence/index/GeoCandidateResult.java | 2 +- .../usergrid/persistence/index/impl/EsEntityIndexImpl.java | 5 +++-- .../apache/usergrid/persistence/index/impl/IndexingUtils.java | 4 +--- .../apache/usergrid/persistence/index/query/ParsedQuery.java | 4 ++++ 6 files changed, 11 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/5cc0b380/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java index dd7a916..fa0e12d 100644 --- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java +++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java @@ -60,6 +60,7 @@ public class EntityToMapConverter { for ( Field field : entity.getFields() ) { if( field instanceof DistanceField){ + //parse distance and add to metadata if(!entityMap.containsKey("metadata"))entityMap.put("metadata",new HashMap<String,Object>()); DistanceField distanceField = (DistanceField) field; Map<String,Object> metaMap = (Map) entityMap.get("metadata"); http://git-wip-us.apache.org/repos/asf/usergrid/blob/5cc0b380/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DistanceField.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DistanceField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DistanceField.java index 4e9e1e1..dd99792 100644 --- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DistanceField.java +++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DistanceField.java @@ -20,7 +20,7 @@ package org.apache.usergrid.persistence.model.field; /** - * Classy class class. + * Distance field to pass distance down the parsing chain. */ public class DistanceField extends DoubleField { public static final String NAME = "distance"; http://git-wip-us.apache.org/repos/asf/usergrid/blob/5cc0b380/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/GeoCandidateResult.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/GeoCandidateResult.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/GeoCandidateResult.java index 07ef41c..dc91be9 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/GeoCandidateResult.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/GeoCandidateResult.java @@ -24,7 +24,7 @@ import org.apache.usergrid.persistence.model.entity.Id; import java.util.UUID; /** - * Classy class class. + * Result for Geo candidates */ public class GeoCandidateResult extends CandidateResult { private final double distance; http://git-wip-us.apache.org/repos/asf/usergrid/blob/5cc0b380/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 b32a11c..0cfa18b 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 @@ -668,12 +668,13 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData { logger.debug( " Hit count: {} Total hits: {}", hits.length, searchHits.getTotalHits() ); List<CandidateResult> candidates = new ArrayList<>( hits.length ); - final boolean isGeo = query.getOriginalQuery().contains("location") && query.getOriginalQuery().contains("within"); + + for ( SearchHit hit : hits ) { CandidateResult candidateResult; - candidateResult = parseIndexDocId( hit, isGeo ); + candidateResult = parseIndexDocId( hit, query.isGeoQuery() ); candidates.add( candidateResult ); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/5cc0b380/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 88da04e..ae2a6e6 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 @@ -222,9 +222,7 @@ public class IndexingUtils { builder.append( type ).append( "(" ).append( value ).append( ")" ); } - /** - * Parse the document id into a candidate result - */ + public static CandidateResult parseIndexDocId( final SearchHit hit ) { return parseIndexDocId(hit.getId()); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/5cc0b380/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java index bb87dcc..1cb3ba2 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/ParsedQuery.java @@ -202,4 +202,8 @@ public class ParsedQuery { public Operand getRootOperand() { return rootOperand; } + + public boolean isGeoQuery(){ + return getOriginalQuery().contains("location") && getOriginalQuery().contains("within"); + } }