Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Solr search scaffold (NOT FOR MERGING) #1476

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ conf/dos.conf*
conf/minio.conf*
conf/api-keys.conf*
solr*
# data which is not yet vetted
test/resources/searchdata.json
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ val projectScalaVersion = "2.13.14"
val appName = "docview"

val backendVersion = "0.15.1"
val dataConverterVersion = "1.1.15"
val dataConverterVersion = "2.0.0"
val alpakkaVersion = "3.0.4"

// This prevents a library version incompatibility error between
Expand Down
64 changes: 64 additions & 0 deletions test/integration/search/SolrSearchSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package integration.search

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.stream.Materializer
import akka.util.ByteString
import eu.ehri.project.search.solr.SolrSearchEngine
import org.specs2.specification.BeforeAfterAll
import play.api.test.{PlaySpecification, WithApplication}
import play.api.{Application, Environment}
import services.ServiceConfig
import services.search.{SearchHit, SearchParams, SearchQuery, SearchResult}

import java.nio.file.Paths
import scala.concurrent.ExecutionContext.Implicits._
import scala.concurrent.Future


class SolrSearchSpec extends PlaySpecification with BeforeAfterAll {

private implicit val system: ActorSystem = ActorSystem.create("search-test")
private implicit val mat: Materializer = Materializer.matFromSystem

"SolrSearch" should {
"response 'ok' to status" in new WithApplication {
val sc = app.injector.instanceOf[SolrSearchEngine]
await(sc.status()) must_== "ok"
}

"return an appropriate number of items on glob select" in new WithApplication {
val r = await(search("*"))
r.page.total must beGreaterThan(4000)
}
}

private def search(q: String)(implicit app: Application): Future[SearchResult[SearchHit]] = {
val params = SearchParams(query = Some(q))
val query = SearchQuery(params = params)
val sc = app.injector.instanceOf[SolrSearchEngine]
sc.search(query)
}

private def solrUpdate(entity: UniversalEntity): Future[String] = {
val url = ServiceConfig("solr", play.api.Configuration.load(Environment.simple())).baseUrl + "/update?commit=true"
val req = HttpRequest(HttpMethods.POST, url).withEntity(entity)
Http().singleRequest(req).flatMap { r =>
val out = r.entity.withoutSizeLimit().dataBytes.runFold(ByteString.empty)(_ ++ _)
out.map(_.utf8String)
}
}

override def beforeAll(): Unit = {
val path = Paths.get(getClass.getClassLoader.getResource("searchdata.json").toURI)
val entity = HttpEntity.fromPath(ContentTypes.`application/json`, path)
await(solrUpdate(entity))
}

override def afterAll(): Unit = {
val deleteQuery = """{"delete": {"query": "*:*"}}"""
val entity = HttpEntity(ContentTypes.`application/json`, deleteQuery)
await(solrUpdate(entity))
}
}
Loading