spray

solr

package solr

Provides a simple Solr DSL using Akka, spray-client and spray-json.

Basic Flow

Example

Setup

Create SolrService actor:

val solrService = system.actorOf(
	props = Props[SolrService],
	name = "solr-service");

Don't forget that you need to have a spray-client running at context.actorFor("../http-client") (relative to the context of the SolrService).

Query

Create query "http://localhost:8983/solr/core1/select?q=test&wt=json&rows=10" with:

val solrQuery = Solr("localhost", 8983, "core1").q("test").rows(10)()

or if you have com.typesafe.config.Config config file with something like

test.solr {
	ip = "localhost"
 	port = 8983
 	core = "/solr/core1"
}

and an akka.actor.ActorSystem with that config in scope:

val solrQuery = Solr("test.solr").q("test").rows(10)()

Then send the request off to the SolrService instance (let's say we have it in scope in solrService) and remember the the future (if doing ask):

val solrResponseFuture = solrService ? solrQuery

Now say you expect the response from Solr to have two fields test1 and test2 with string values and you want those end up in a nice case class like:

case class SolrTestResult(val test1: String, val test2: String)

You need to get a spray-json formatter for SolrTestResult into scope. You can find out how to do that in the spray-json documentation.

One you have that you can get the list of results:

solrResponseFuture onSuccess {
	case solrResponse: SolrResults => {
		val testResults: List[SolrTestResult] = solrResponse.as[SolrTestResult]
		// do something with the results
	}
	case SolrError => {
		// handle the error
 }
}
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. solr
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class EmptyReply[T](error: String) extends SolrResponse[T] with Product with Serializable

  2. case class Response[T](numFound: Int, start: Int, docs: List[T]) extends Product with Serializable

  3. case class ResponseHeader(status: Int, QTime: Int, params: Map[String, String]) extends Product with Serializable

  4. class Solr extends AnyRef

    Constructs a Solr query.

  5. class SolrImport extends AnyRef

    Constructs a Solr dataimport query.

  6. case class SolrQuery(host: String, port: Int, content: String) extends Product with Serializable

  7. case class SolrReply[T](responseHeader: ResponseHeader, response: Response[T]) extends SolrResponse[T] with Product with Serializable

  8. abstract class SolrResponse[T] extends AnyRef

  9. case class SolrResults(response: HttpEntity) extends SolrServiceResponse with Product with Serializable

  10. class SolrService extends Actor with ActorLogging

  11. abstract class SolrServiceResponse extends AnyRef

Value Members

  1. object Solr

    Factory for Solr query builders

  2. object SolrError extends SolrServiceResponse with Product with Serializable

  3. object SolrJsonProtocol extends DefaultJsonProtocol

Inherited from AnyRef

Inherited from Any

Ungrouped