Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added test and fixed bug in sorting when the index isn't optimized.

  • Loading branch information...
commit f6aa243f60f0a475e5ab179eefc4b72a5390e4d0 1 parent 5c54ef1
@dsmiley authored
View
24 src/main/java/solr2155/solr/search/function/GeoHashValueSource.java
@@ -23,6 +23,7 @@
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.solr.schema.FieldType;
import org.apache.solr.search.FunctionQParser;
+import org.apache.solr.search.SolrIndexReader;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.MultiValueSource;
@@ -67,7 +68,10 @@ public static ValueSource getValueSource(String fieldName, FunctionQParser parse
private final Logger log = LoggerFactory.getLogger(getClass());
- //admittedly the List<Point2D> part isn't particularly memory efficient or kind to the GC.
+ /**
+ * A multi-value cache across the entire index (all Lucene segments).
+ * Admittedly the List<Point2D> part isn't particularly memory efficient or kind to the GC.
+ */
private List<Point2D>[] doc2PointsCache;//index by doc id, then list of points
@SuppressWarnings({"unchecked"})
@@ -143,6 +147,12 @@ public int dimension() {
/** This class is public so that {@link #point2Ds(int)} is exposed. */
public class GeoHashDocValues extends DocValues {
+ private final int docIdBase;
+
+ public GeoHashDocValues(int docIdBase) {
+ this.docIdBase = docIdBase;
+ }
+
@Override
public void doubleVal(int doc, double[] vals) {
super.doubleVal(doc, vals);//TODO
@@ -152,10 +162,11 @@ public void doubleVal(int doc, double[] vals) {
* Do NOT modify the returned array! May return null.
*/
public List<Point2D> point2Ds(int doc) {
+ //This cache is over the entire index (all Lucene segments).
final List<Point2D>[] cache = GeoHashValueSource.this.doc2PointsCache;
if (cache == null)
return null;
- return cache[doc];
+ return cache[docIdBase+doc];
}
@Override
@@ -173,11 +184,14 @@ public String toString(int doc) {
}
}
- private final GeoHashDocValues docValues = new GeoHashDocValues();
-
@Override
public GeoHashDocValues getValues(Map context, IndexReader reader) throws IOException {
- return docValues;
+ int docIdBase = 0;
+ if (reader instanceof SolrIndexReader) {
+ SolrIndexReader solrIndexReader = (SolrIndexReader) reader;
+ docIdBase = solrIndexReader.getBase();
+ }
+ return new GeoHashDocValues(docIdBase);
}
@Override
View
15 src/test/java/solr2155/solr/search/function/distance/MultiDistanceFunctionTest.java
@@ -79,6 +79,21 @@ public void testGeoMultiDist() throws Exception {
"d", "1000", "sfield", "store", "sort", "geodist() asc"), "//doc[1]/str[@name='id']='2'");
}
+ @Test
+ public void testSortMultiSegmentBug() throws Exception {
+ clearIndex();
+ assertU(adoc("id", "Denver, CO (SMD)", "store", "39.740009,-104.992264"));
+ //assertU(adoc("id", "Denver, CO (MFNPA)", "store", "39.728024,-104.990250"));
+ assertU(commit());//make a new segment
+ assertU(adoc("id", "San Antonio, TX", "store", "31.436729,-99.306923"));
+ assertU(adoc("id", "Denver, CO (DSANDO)", "store", "39.718670,-104.988907"));
+ assertU(commit());
+
+ assertQ(req("fl", "*,score", "q", "*:*", "sfield", "store", "pt", "39.740112,-104.984856",
+ "d", "100", "sfield", "store", "sort", "geodist() asc"),
+ "//doc[position()=last()]/str[@name='id']='San Antonio, TX'"
+ );
+ }
/** TODO propose that this go into Solr's test harness. */
private void assertQScore(SolrQueryRequest req, int docIdx, float targetScore) throws Exception {
Please sign in to comment.
Something went wrong with that request. Please try again.