Permalink
Browse files

Fix everything

  • Loading branch information...
1 parent a7513ed commit 7739460305a1a1d6382cdb35864316e38bfd4a05 Holden Karau committed May 25, 2012
@@ -1 +1 @@
-plugin=com.foursquare.elasticsearch.scorer
+plugin=com.foursquare.elasticsearch.scorer.FourSquareScorePlugin
@@ -12,6 +12,6 @@ class FourSquareScorePlugin extends AbstractPlugin {
override def description(): String = "foursquare plugin";
def onModule(module: ScriptModule): Unit = {
- module.registerScript("distance_score_magic", classOf[CombinedDistanceDocumentScorerSearchScript#Factory]);
+ module.registerScript("distance_score_magic", classOf[ScoreFactory]);
}
}
@@ -19,17 +19,6 @@ case class CombinedDistanceDocumentScorerSearchScript(val lat: Double,
val weight1: Float,
val weight2: Float) extends AbstractFloatSearchScript {
- class Factory extends NativeScriptFactory {
- def newScript(@Nullable params: Map[String, Object]): ExecutableScript = {
- val lat: Double = if (params == null) 1 else XContentMapValues.nodeDoubleValue(params.get("lat"), 0);
- val lon: Double = if (params == null) 1 else XContentMapValues.nodeDoubleValue(params.get("lon"), 0);
- val weight1: Float = if(params == null) 1 else XContentMapValues.nodeFloatValue(params.get("weight1"), 5000.0f);
- val weight2: Float = if(params == null) 1 else XContentMapValues.nodeFloatValue(params.get("weight2"), 0.05f);
- return new CombinedDistanceDocumentScorerSearchScript(lat, lon, weight1, weight2);
- }
- }
-
-
override def runAsFloat(): Float = {
val myDoc: DocLookup = doc();
val point: GeoPointDocFieldData = myDoc.get("point").asInstanceOf[GeoPointDocFieldData];
@@ -41,3 +30,13 @@ case class CombinedDistanceDocumentScorerSearchScript(val lat: Double,
myScore
}
}
+
+class ScoreFactory extends NativeScriptFactory {
+ def newScript(@Nullable params: Map[String, Object]): ExecutableScript = {
+ val lat: Double = if (params == null) 1 else XContentMapValues.nodeDoubleValue(params.get("lat"), 0);
+ val lon: Double = if (params == null) 1 else XContentMapValues.nodeDoubleValue(params.get("lon"), 0);
+ val weight1: Float = if(params == null) 1 else XContentMapValues.nodeFloatValue(params.get("weight1"), 5000.0f);
+ val weight2: Float = if(params == null) 1 else XContentMapValues.nodeFloatValue(params.get("weight2"), 0.05f);
+ return new CombinedDistanceDocumentScorerSearchScript(lat, lon, weight1, weight2);
+ }
+}
@@ -9,7 +9,9 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.search.geo.GeoDistance;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
-import org.testng.annotations.Test;
+
+import org.junit.Test
+import org.junit._
import java.util.Arrays;
@@ -52,7 +54,7 @@ class DistanceScoreMagicSearchScriptTests {
// we rely here on score being 1 since we are using match_all
val distance: Double = GeoDistance.PLANE.calculate(40.7143528, -74.0059731, 40.759011, -73.9844722, DistanceUnit.KILOMETERS);
- assertThat(searchResponse.hits().getAt(0).score().asInstanceOf[java.lang.Double],
+ assertThat(searchResponse.hits().getAt(0).score().toDouble.asInstanceOf[java.lang.Double],
closeTo(((1 + 2000 * math.pow(((1.0 * (math.pow(distance, 2.0))) + 1.0), -1.0)
+ 3 * 0.03).asInstanceOf[java.lang.Double]),
0.00001.asInstanceOf[java.lang.Double]));

0 comments on commit 7739460

Please sign in to comment.