Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v1.0.3

  • Loading branch information...
commit 238b3eb957f16ae0bc74ed69e00e8dffb4423700 1 parent 476378e
@dsmiley authored
View
7 README.txt
@@ -13,4 +13,11 @@ Instructions:
<queryParser name="gh_geofilt" class="solr2155.solr.search.SpatialGeoHashFilterQParser$Plugin" />
<!-- replace built-in geodist() with our own modified one -->
<valueSourceParser name="geodist" class="solr2155.solr.search.function.distance.HaversineConstFunction$HaversineValueSourceParser" />
+
+ Add the following cache into <query> section if you are going to use geodist func
+ <cache name="fieldValueCache"
+ class="solr.FastLRUCache"
+ size="10"
+ initialSize="1"
+ autowarmCount="1"/>
View
2  pom.xml
@@ -6,7 +6,7 @@
<groupId>Solr2155</groupId>
<artifactId>Solr2155</artifactId>
- <version>1.0.2</version>
+ <version>1.0.3</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
View
11 src/main/java/solr2155/solr/search/SpatialGeoHashFilterQParser.java
@@ -22,7 +22,6 @@
import org.apache.lucene.spatial.DistanceUtils;
import org.apache.lucene.spatial.tier.InvalidGeoException;
import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.DefaultSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@@ -52,8 +51,8 @@
* <li>Point-radius (AKA distance) / circle: point, radius. point is "lat,lon" and radius is the distance in meters
* forming the circle.</li>
* <li>Bounding box: box. "west,south,east,north" in degrees</li>
- * <li>Polygon: polygon. See {@link JtsGeom#parsePolygon(String)}</li>
- * <li>WKT geometry: geometry. {@link JtsGeom#parseGeometry(String)}</li>
+ * <li>Polygon: polygon. NOT IMPLEMENTED</li>
+ * <li>WKT geometry: geometry. NOT IMPLEMENTED</li>
* </ul>
* NOTE: Polygon & WKT geometry require a separate module which in turn requires the LGPL licensed JTS library.
*/
@@ -70,7 +69,6 @@ public SpatialGeoHashFilterQParser(String qstr, SolrParams localParams, SolrPara
protected SolrParams defaultParams;
- @Override
public void init(NamedList args) {
defaultParams = SolrParams.toSolrParams(args);
}
@@ -85,10 +83,11 @@ public QParser createParser(String qstr, SolrParams localParams, SolrParams para
@Override
public Query parse() throws ParseException {
- String field = localParams.get("sfield");
+ final String SFIELD = "sfield";
+ String field = localParams.get(SFIELD);
if (field == null)
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- CommonParams.FL + " is not properly specified");
+ SFIELD + " is not properly specified"+" in local params");
SchemaField schemaField = req.getSchema().getField(field);
final FieldType fieldType = schemaField.getType();
if (!(fieldType instanceof GeoHashField))
View
52 src/main/java/solr2155/solr/search/function/distance/HaversineMultiConstFunction.java
@@ -25,8 +25,8 @@
import solr2155.solr.search.function.GeoHashValueSource;
import java.io.IOException;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import static java.util.Collections.*;
/**
* Haversine function for use with {@link GeoHashValueSource} in which multiple points are supported.
@@ -80,11 +80,7 @@ public double doubleVal(int doc) {
double distance = 0.0; // this will be overlaid
boolean firstLap = true;
for (Point2D point : geoList) {
- double lat = point.getY();
- double lon = point.getX();
- double latRad = lat * DistanceUtils.DEGREES_TO_RADIANS;
- double lonRad = lon * DistanceUtils.DEGREES_TO_RADIANS;
- double distanceNew = DistanceUtils.haversine(latCenterRad, lonCenterRad, latRad, lonRad, DistanceUtils.EARTH_MEAN_RADIUS_KM);
+ double distanceNew = distance(point);
if ((firstLap) ||
(asc == true && distanceNew < distance) ||
(asc == false && distanceNew > distance)) {
@@ -95,13 +91,53 @@ public double doubleVal(int doc) {
return distance;
}
+ private double distance(Point2D point) {
+ double lat = point.getY();
+ double lon = point.getX();
+ double latRad = lat * DistanceUtils.DEGREES_TO_RADIANS;
+ double lonRad = lon * DistanceUtils.DEGREES_TO_RADIANS;
+ double distanceNew = DistanceUtils.haversine(latCenterRad, lonCenterRad, latRad, lonRad, DistanceUtils.EARTH_MEAN_RADIUS_KM);
+ return distanceNew;
+ }
+
public String strVal(int doc) {
return Double.toString(doubleVal(doc));
}
@Override
public String toString(int doc) {
- return name() + '(' + ghDocVals.strVal(doc) + ',' + latCenter + ',' + lonCenter + ')';
+ int maxPoints = 3;
+ List<Point2D> geoList = ghDocVals.point2Ds(doc);
+ boolean truncated = false;
+
+ TreeMap<Double, Point2D> heap = new TreeMap<Double, Point2D>(
+ !asc ? reverseOrder() : reverseOrder(reverseOrder()));
+ for (Point2D p : geoList == null ? Collections.<Point2D>emptyList() : geoList) {
+ heap.put(distance(p), p);
+ if (!heap.isEmpty() && heap.size() > maxPoints) {
+ heap.remove(heap.lastKey());
+ truncated = true;
+ }
+ }
+ return name() + '(' + dump(heap.values()) +
+ (truncated ? "..." : "") +
+ ',' + latCenter + ',' + lonCenter + ')';
+ }
+
+ private StringBuilder dump(Collection<Point2D> points) {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (Point2D p : points) {
+ if (!first) {
+ sb.append(' ');
+ }
+ sb.append(p.getY());
+ sb.append(',');
+ sb.append(p.getX());
+
+ first = false;
+ }
+ return sb;
}
};
}
Please sign in to comment.
Something went wrong with that request. Please try again.