Github user isper3at commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/187#discussion_r129987379 --- Diff: extras/rya.geoindexing/src/main/java/org/apache/rya/indexing/accumulo/geo/GeoTupleSet.java --- @@ -349,6 +371,100 @@ public String toString() { }; }; + private final SearchFunction GEO_NEAR = new SearchFunction() { + @Override + public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText, + final StatementConstraints contraints) throws QueryEvaluationException { + try { + final String[] args = queryText.split(NEAR_DELIM); + Optional<Double> maxDistanceOpt = Optional.empty(); + Optional<Double> minDistanceOpt = Optional.empty(); + final String query = args[0]; + + for (int ii = 1; ii < args.length; ii++) { + String numArg = args[ii]; + + // remove pre-padding 0's since NumberUtils.isNumber() + // will assume its octal if it starts with a 0. + while (numArg.startsWith("0")) { + numArg = numArg.substring(1); + } + // was 0 + if (numArg.equals("")) { + // if max hasn't been set, set it to 0. + // Otherwise, min is just ignored. + if (!maxDistanceOpt.isPresent()) { + maxDistanceOpt = Optional.of(0.0); + } + } else { + if (!maxDistanceOpt.isPresent() && NumberUtils.isNumber(numArg)) { + // no variable identifier, going by order. + maxDistanceOpt = getDistanceOpt(numArg, "maxDistance"); + } else if (NumberUtils.isNumber(numArg)) { + // no variable identifier, going by order. + minDistanceOpt = getDistanceOpt(numArg, "minDistance"); + } else { + throw new IllegalArgumentException(numArg + " is not a valid Near function argument."); + } + } + } + final WKTReader reader = new WKTReader(); + final Geometry geometry = reader.read(query); + final NearQuery nearQuery = new NearQuery(maxDistanceOpt, minDistanceOpt, geometry); + return geoIndexer.queryNear(nearQuery, contraints); + } catch (final ParseException e) { + throw new QueryEvaluationException(e); + } + } + + private Optional<Double> getDistanceOpt(final String num, final String name) { + try { + return Optional.of(Double.parseDouble(num)); + } catch (final NumberFormatException nfe) { --- End diff -- ok, so it can't be negative. good catch. Adding a check for that now
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---