Permalink
Browse files

Fix onLoad and cleanup spacing

  • Loading branch information...
Holden Karau
Holden Karau committed May 17, 2012
1 parent 6de668e commit a7513ed50d74c94b9fd5d633fa99f9057180d178
@@ -4,13 +4,14 @@ import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.script.ScriptModule;
/**
+ * Provides a fast* score script for our primary use case
*/
class FourSquareScorePlugin extends AbstractPlugin {
- override def name(): String = "foursquare";
+ override def name(): String = "foursquare";
- override def description(): String = "foursquare plugin";
+ override def description(): String = "foursquare plugin";
- def onModule(module: ScriptModule): Unit = {
- //module.registerScript("distance_score_magic", DistanceScoreMagicSearchScript.Factory.class);
- }
+ def onModule(module: ScriptModule): Unit = {
+ module.registerScript("distance_score_magic", classOf[CombinedDistanceDocumentScorerSearchScript#Factory]);
+ }
}
@@ -15,29 +15,29 @@ import java.util.Map;
* Note: assumes that the point field is point
*/
case class CombinedDistanceDocumentScorerSearchScript(val lat: Double,
- val lon: Double,
- val weight1: Float,
- val weight2: Float) extends AbstractFloatSearchScript {
+ val lon: 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);
- }
+ 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];
- val popularity: Double = myDoc.numeric("decayedPopularity1").asInstanceOf[NumericDocFieldData[_]].getDoubleValue()
- // up to you to remove score from here or not..., also, possibly, add more weights options
- val myScore: Float = (score() *
- (1 + weight1 * math.pow(((1.0 * (math.pow(point.distanceInKm(lat, lon), 2.0))) + 1.0), -1.0)
- + popularity * weight2)).toFloat;
- myScore
- }
+ override def runAsFloat(): Float = {
+ val myDoc: DocLookup = doc();
+ val point: GeoPointDocFieldData = myDoc.get("point").asInstanceOf[GeoPointDocFieldData];
+ val popularity: Double = myDoc.numeric("decayedPopularity1").asInstanceOf[NumericDocFieldData[_]].getDoubleValue()
+ // up to you to remove score from here or not..., also, possibly, add more weights options
+ val myScore: Float = (score() *
+ (1 + weight1 * math.pow(((1.0 * (math.pow(point.distanceInKm(lat, lon), 2.0))) + 1.0), -1.0)
+ + popularity * weight2)).toFloat;
+ myScore
+ }
}

0 comments on commit a7513ed

Please sign in to comment.