Permalink
Browse files

Add a test for score of 0.0 and notice the comment saying it blows up…

… is no longer correct, remove comment.
  • Loading branch information...
1 parent e309b09 commit d18e569f37857e5ba3a43dd491122f28c1fe7eed @holdenk committed Jan 17, 2013
@@ -634,7 +634,6 @@ trait ElasticSchema[M <: Record[M]] extends SlashemSchema[M] {
val esHits = response.getHits().getHits()
val docs: Array[(Map[String,Any], Option[Map[String,java.util.ArrayList[String]]])] = esHits.map(doc => {
val m = doc.sourceAsMap()
- //If a score is 0.0 this will blow up :(
val scoreDouble = doc.score().toDouble
val annotedMap = (m.asScala ++ List("score" -> scoreDouble)).toMap
val hlf = doc.getHighlightFields()
@@ -17,14 +17,15 @@ import java.util.Map;
case class CombinedDistanceDocumentScorerSearchScript(val lat: Double,
val lon: Double,
val weight1: Float,
- val weight2: Float) extends AbstractFloatSearchScript {
+ val weight2: Float,
+ val weight3: Float) extends AbstractFloatSearchScript {
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() *
+ val myScore: Float = weight3 * (score() *
(1 + weight1 * math.pow(((1.0 * (math.pow(point.distanceInKm(lat, lon), 2.0))) + 1.0), -1.0)
+ popularity * weight2)).toFloat;
myScore
@@ -37,6 +38,7 @@ class ScoreFactory extends NativeScriptFactory {
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);
+ val weight3: Float = if(params == null) 1 else XContentMapValues.nodeFloatValue(params.get("weight3"), 1.00f);
+ return new CombinedDistanceDocumentScorerSearchScript(lat, lon, weight1, weight2, weight3);
}
}
@@ -538,6 +538,14 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
Assert.assertEquals(response1.response.results.length, 2)
}
+ @Test
+ def testZeroZeroScore {
+ val params: Map[String, Any] = Map("lat" -> -31.1, "lon" -> 74.0, "weight" -> 0, "weight2" -> 0, "weight3" -> 0)
+ val response1 = ESimpleGeoPanda where(_.name contains "lolerskates") customScore("distance_score_magic", params) fetch()
+ Assert.assertEquals(response1.response.results.length, 2)
+ }
+
+
def testFilters {
// grab 2 results, filter to 1
val res1 = ESimplePanda where (_.hugenums contains 1L) filter(_.nicknamesString in List("jerry")) fetch()

0 comments on commit d18e569

Please sign in to comment.