Request Interception

Solrs allows to intercept queries sent to Solr, here’s an example that shows how to log details about each request:

val loggingInterceptor = new RequestInterceptor {
  override def interceptQuery(f: (SolrServer, SolrQuery) => Future[QueryResponse])
                             (solrServer: SolrServer, q: SolrQuery): Future[QueryResponse] = {
    val start = System.currentTimeMillis()
    f(solrServer, q).map { qr =>
      val requestTime = System.currentTimeMillis() - start"Query $q to $solrServer took $requestTime ms (query time in solr: ${qr.getQTime} ms).")

val solr = AsyncSolrClient.Builder("http://localhost:8983/solr/collection1")
Full source at GitHub
The source code for this page can be found here.