From 7f4c82c0d6ee312e106cc237ed47ceb8d6ddc378 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Thu, 30 Sep 2010 21:26:47 +0000 Subject: [PATCH] SOLR-1568: add field queries and range queries to LatLonType git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1003291 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/schema/LatLonType.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/solr/src/java/org/apache/solr/schema/LatLonType.java b/solr/src/java/org/apache/solr/schema/LatLonType.java index ccaae1d0793..ae9553bac14 100644 --- a/solr/src/java/org/apache/solr/schema/LatLonType.java +++ b/solr/src/java/org/apache/solr/schema/LatLonType.java @@ -84,6 +84,49 @@ public class LatLonType extends AbstractSubTypeFieldType implements SpatialQuery } + @Override + public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) { + int dimension = 2; + + String[] p1; + String[] p2; + try { + p1 = DistanceUtils.parsePoint(null, part1, dimension); + p2 = DistanceUtils.parsePoint(null, part2, dimension); + } catch (InvalidGeoException e) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); + } + BooleanQuery result = new BooleanQuery(true); + for (int i = 0; i < dimension; i++) { + SchemaField subSF = subField(field, i); + // points must currently be ordered... should we support specifying any two opposite corner points? + result.add(subSF.getType().getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST); + } + return result; + + } + + @Override + public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) { + int dimension = 2; + + String[] p1 = new String[0]; + try { + p1 = DistanceUtils.parsePoint(null, externalVal, dimension); + } catch (InvalidGeoException e) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); + } + BooleanQuery bq = new BooleanQuery(true); + for (int i = 0; i < dimension; i++) { + SchemaField sf = subField(field, i); + Query tq = sf.getType().getFieldQuery(parser, sf, p1[i]); + bq.add(tq, BooleanClause.Occur.MUST); + } + return bq; + } + + + @Override public Query createSpatialQuery(QParser parser, SpatialOptions options) { double[] point = null;