Permalink
Browse files

Make scoring more like lucene scoring and work around low value score…

…s breaking
  • Loading branch information...
1 parent 7ac8fd2 commit 06b01cd3c204a661e59a67995abbd6e94f1eb40b @holdenk committed Aug 21, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/main/scala/com/foursquare/slashem/Schema.scala
@@ -630,7 +630,9 @@ 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()
- val annotedMap = (m.asScala ++ List("score" -> doc.score().toDouble)).toMap
+ //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()
if (hlf == null) {
Pair(annotedMap,None)
@@ -747,11 +749,12 @@ trait ElasticSchema[M <: Record[M]] extends SlashemSchema[M] {
def scoreFields(query: ElasticQueryBuilder, fieldsToScore: List[ScoreBoost]): ElasticQueryBuilder = {
val scoredFields = fieldsToScore.map(_.elasticBoost)
val params = scoredFields.flatMap(_._1)
- val scriptSrc = scoredFields.map(_._2).mkString(" + ")
+ val scriptSrc = scoredFields.map(_._2).mkString(" * ")
val paramNames = (1 to params.length).map("p"+_)
val script = scriptSrc.format(paramNames:_*)
val namesAndParams = paramNames.zip(params).toMap
- val scoreScript = "_score * (1 +"+ script + " )"
+ //The ES client library breaks badly with low score values
+ val scoreScript = "1.0 + _score * "+ script + ""
scoreWithScript(query, scoreScript, namesAndParams, false)
}
@@ -1434,7 +1437,7 @@ class PointField[T <: Record[T]](override val owner: T) extends Field[Pair[Doubl
try {
a match {
case "" => Empty
- /*
+ /*
* GeoJSON has (long, lat) instead of (lat, long)
* Only ES uses GeoJSON spec and returns an ArrayList
*

0 comments on commit 06b01cd

Please sign in to comment.