Permalink
Browse files

Add tracking for # of results & add success/failure tracking to ES

* After discussions with Shay it seems like # of matching
  documents could be a useful performance metric for instances
  where we are using the custom_scorer, so provide a hook to
  easily track this.

* Add onSuccess and onFailure tracking for ES queries

* Bump version to 0.9.9b
  • Loading branch information...
1 parent 7c92bd1 commit d09a5e69631a2542e2a2829ab5fb5614235531f3 Holden Karau committed Apr 13, 2012
Showing with 16 additions and 3 deletions.
  1. +1 −1 build.sbt
  2. +15 −2 src/main/scala/com/foursquare/slashem/Schema.scala
View
@@ -1,6 +1,6 @@
name := "slashem"
-version := "0.9.9a"
+version := "0.9.9b"
organization := "com.foursquare"
@@ -390,12 +390,16 @@ trait SolrQueryLogger {
//Log success
def success(name: String): Unit = {
}
+ //Log the number of results
+ def resultCount(name: String, count: Int): Unit = {
+ }
}
/** The default logger, does nothing. */
object NoopQueryLogger extends SolrQueryLogger {
override def log(name: String, msg: String, time: Long) = Unit
override def debug(msg: String) = println(msg)
+ override def resultCount(name: String, count:Int) = println("Got back "+count+" results while querying "+name)
}
//If you want any of the geo queries you will have to implement this
@@ -507,9 +511,11 @@ trait ElasticSchema[M <: Record[M]] extends SlashemSchema[M] {
response
}
+ val queryText = query.toString()
+
timeFuture(searchResultsFuture).map( {
case (queryTime, result) => {
- meta.logger.log("e" + meta.indexName + ".query",query.toString(), queryTime)
+ meta.logger.log("e" + meta.indexName + ".query",queryText, queryTime)
result
}}).map({
response =>
@@ -522,6 +528,11 @@ trait ElasticSchema[M <: Record[M]] extends SlashemSchema[M] {
results
})
+ .onSuccess((v: SearchResults[M,Y]) => {
+ meta.logger.success("e"+meta.indexName)
+ meta.logger.resultCount("e"+meta.indexName,v.response.numFound)})
+ .onFailure(e => meta.logger.failure("e"+meta.indexName, queryText, e))
+
}
def constructSearchResults[Y](creator: Option[Response.RawDoc => Y],
start: Int,
@@ -723,7 +734,9 @@ trait SolrSchema[M <: Record[M]] extends SlashemSchema[M] {
min,
queryText)
})
- .onSuccess(_ => meta.logger.success(meta.solrName))
+ .onSuccess((v: SearchResults[M,Y]) => {
+ meta.logger.success(meta.solrName)
+ meta.logger.resultCount(meta.solrName,v.response.numFound)})
.onFailure(e => meta.logger.failure(meta.solrName, queryText, e))
}

0 comments on commit d09a5e6

Please sign in to comment.