Permalink
Browse files

Work around for small scores

  • Loading branch information...
1 parent 8253a75 commit daf1ef2a5e93e0d6ec275b17f0630cf63735a2eb @holdenk holdenk committed Aug 6, 2012
View
2 ...ala/com/foursquare/elasticsearch/scorer/script/CombinedDistanceDocumentScorerScript.scala
@@ -24,7 +24,7 @@ case class CombinedDistanceDocumentScorerSearchScript(val lat: Double,
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() *
+ val myScore: Float = (1.0+ score() *
(0 + weight1 * math.pow(((1.0 * (math.pow(point.distanceInKm(lat, lon), 2.0))) + 1.0), -1.0)
* popularity * weight2)).toFloat;
myScore
View
2 src/test/scala/com/foursquare/elasticsearch/scorer/ScorerTest.scala
@@ -55,7 +55,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().toDouble.asInstanceOf[java.lang.Double],
- closeTo(((2000 * math.pow(((1.0 * (math.pow(distance, 2.0))) + 1.0), -1.0)
+ 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 daf1ef2

Please sign in to comment.