Index: contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java =================================================================== --- contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java (revision 759164) +++ contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java (working copy) @@ -138,9 +138,9 @@ addPoint(writer,"Iota Club and Cafe",38.8890000,-77.0923000); addPoint(writer,"Hilton Washington Embassy Row",38.9103000,-77.0451000); addPoint(writer,"HorseFeathers, Bar & Grill", 39.01220000000001, -77.3942); - writer.flush(); + writer.commit(); - //writer.close(); + writer.close(); } public void testRange() throws IOException, InvalidGeoException { @@ -179,12 +179,12 @@ // As the radius filter has performed the distance calculations // already, pass in the filter to reuse the results. // - DistanceSortSource dsort = new DistanceSortSource(dq.distanceFilter); - Sort sort = new Sort(new SortField("foo", dsort)); + DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter); + Sort sort = new Sort(new SortField("foo", dsort,false)); // Perform the search, using the term query, the serial chain filter, and the // distance sort - Hits hits = searcher.search(customScore, dq.getFilter()); //,sort); + Hits hits = searcher.search(customScore, dq.getFilter(),sort); int results = hits.length(); @@ -206,7 +206,7 @@ assertEquals(14, distances.size()); assertEquals(7, results); - + double lastDistance = 0; for(int i =0 ; i < results; i++){ Document d = hits.doc(i); @@ -217,9 +217,11 @@ double distance = DistanceUtils.getInstance().getDistanceMi(lat, lng, rsLat, rsLng); double llm = DistanceUtils.getInstance().getLLMDistance(lat, lng, rsLat, rsLng); - System.out.println("Name: "+ name +", Distance (res, ortho, harvesine):"+ distance +" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i)); + System.out.println("Name: "+ name +", Distance "+ distance); //(res, ortho, harvesine):"+ distance +" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i)); assertTrue(Math.abs((distance - llm)) < 1); assertTrue((distance < miles )); + assertTrue(geo_distance > lastDistance); + lastDistance = geo_distance; } } @@ -302,6 +304,7 @@ System.out.println("Name: "+ name +", Distance (res, ortho, harvesine):"+ distance +" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i)); assertTrue(Math.abs((distance - llm)) < 1); assertTrue((distance < miles )); + } } Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java (revision 759164) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java (working copy) @@ -33,7 +33,8 @@ /** * An implementation of org.apache.lucene.search.RangeFilter that * caches values extracted from the index. - * + * @deprecated + * @see CartesianShapeFilter */ public class BoundaryBoxFilter extends Filter { Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java (revision 759164) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceSortSource.java (working copy) @@ -26,6 +26,11 @@ import org.apache.lucene.search.SortComparatorSource; import org.apache.lucene.search.SortField; +/** + * + * @deprecated + * @see DistanceFieldComparatorSource + */ public class DistanceSortSource implements SortComparatorSource { private static final long serialVersionUID = 1L; Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java (revision 759164) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceQueryBuilder.java (working copy) @@ -142,6 +142,11 @@ return new ConstantScoreQuery(getFilter()); } + + public Query getQuery(Query query){ + return new ConstantScoreQuery(getFilter(query)); + } + public double getLat() { return lat; } Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java (revision 0) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java (revision 0) @@ -0,0 +1,130 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.spatial.tier; + +import java.io.IOException; + +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.search.Filter; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.FieldComparator; +import org.apache.lucene.search.FieldComparatorSource; +import org.apache.lucene.search.SortField; + +public class DistanceFieldComparatorSource extends FieldComparatorSource { + + private static final long serialVersionUID = 1L; + + private DistanceFilter distanceFilter; + private DistanceScoreDocLookupComparator dsdlc; + + public DistanceFieldComparatorSource(Filter distanceFilter) { + + this.distanceFilter = (DistanceFilter) distanceFilter; + + } + + public void cleanUp() { + distanceFilter = null; + + if (dsdlc != null) + dsdlc.cleanUp(); + + dsdlc = null; + } + + @Override + public FieldComparator newComparator(String fieldname, + IndexReader[] subReaders, int numHits, int sortPos, boolean reversed) + throws IOException { + dsdlc = new DistanceScoreDocLookupComparator(distanceFilter, numHits); + return dsdlc; + } + + private class DistanceScoreDocLookupComparator extends FieldComparator { + + private DistanceFilter distanceFilter; + private double[] values; + private double bottom; + + public DistanceScoreDocLookupComparator(DistanceFilter distanceFilter, int numHits) { + this.distanceFilter = distanceFilter; + values = new double[numHits]; + return; + } + + @Override + public int compare(int slot1, int slot2) { + double a = values[slot1]; + double b = values[slot2]; + if (a > b) + return 1; + if (a < b) + return -1; + + return 0; + } + + + + public void cleanUp() { + distanceFilter = null; + } + + @Override + public int compareBottom(int doc, float score) { + final double v2 = distanceFilter.getDistance(doc); + if (bottom > v2) { + return 1; + } else if (bottom < v2) { + return -1; + } + return 0; + } + + @Override + public void copy(int slot, int doc, float score) { + values[slot] = distanceFilter.getDistance(doc); + } + + @Override + public void setBottom(int slot) { + this.bottom = values[slot]; + + } + + @Override + public void setNextReader(IndexReader reader, int docBase, int numSlotsFull) + throws IOException { + // TODO Auto-generated method stub + + } + + @Override + public Comparable value(int slot) { + return values[slot]; + } + + @Override + public int sortType() { + + return SortField.DOUBLE; + } + } + +}