From f6d18fc349afc18b08030d0050fcdf05a6ccd524 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Thu, 23 Sep 2010 19:59:55 +0000 Subject: [PATCH] SOLR-1568: spatial - make sfilt fall back to request params git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1000597 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/solr/common/params/SpatialParams.java | 1 + .../apache/solr/search/SpatialFilterQParser.java | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/solr/src/common/org/apache/solr/common/params/SpatialParams.java b/solr/src/common/org/apache/solr/common/params/SpatialParams.java index a229747ec5a..e57c14350cc 100644 --- a/solr/src/common/org/apache/solr/common/params/SpatialParams.java +++ b/solr/src/common/org/apache/solr/common/params/SpatialParams.java @@ -24,6 +24,7 @@ package org.apache.solr.common.params; public interface SpatialParams { public static final String POINT = "pt"; public static final String DISTANCE = "d"; + public static final String FIELD = "sfield"; // the field that contains the points we are measuring from "pt" /** * km - kilometers * mi - miles diff --git a/solr/src/java/org/apache/solr/search/SpatialFilterQParser.java b/solr/src/java/org/apache/solr/search/SpatialFilterQParser.java index 5749afb008d..dd73ca9080b 100644 --- a/solr/src/java/org/apache/solr/search/SpatialFilterQParser.java +++ b/solr/src/java/org/apache/solr/search/SpatialFilterQParser.java @@ -68,25 +68,31 @@ public class SpatialFilterQParser extends QParser { //TODO: Should we accept multiple fields String[] fields = localParams.getParams(CommonParams.FL); if (fields == null || fields.length == 0) { - throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, CommonParams.FL + " is not properly specified"); + String field = getParam(SpatialParams.FIELD); + if (field == null) + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, " missing field for spatial request"); + fields = new String[] {field}; } - String pointStr = params.get(SpatialParams.POINT); + + String pointStr = getParam(SpatialParams.POINT); if (pointStr == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, SpatialParams.POINT + " is not properly specified"); } - double dist = params.getDouble(SpatialParams.DISTANCE, -1); + double dist = -1; + String distS = getParam(SpatialParams.DISTANCE); + if (distS != null) dist = Double.parseDouble(distS); + if (dist < 0) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, SpatialParams.DISTANCE + " must be >= 0"); } - IndexSchema schema = req.getSchema(); String measStr = localParams.get(SpatialParams.MEASURE); //TODO: Need to do something with Measures Query result = null; //fields is valid at this point if (fields.length == 1) { - SchemaField sf = schema.getField(fields[0]); + SchemaField sf = req.getSchema().getField(fields[0]); FieldType type = sf.getType(); if (type instanceof SpatialQueryable) {