Skip to content

Commit

Permalink
fix(responses): Fix various responses formats (#460)
Browse files Browse the repository at this point in the history
Closes #443
  • Loading branch information
ElPicador authored Feb 13, 2018
1 parent 8204e7e commit f6ad92c
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.15
sbt.version=0.13.15
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")

//Formatter
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.6.8")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.6.8")
12 changes: 6 additions & 6 deletions src/main/scala/algolia/AlgoliaHttpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ case class AlgoliaHttpClient(
.setRequestTimeout(configuration.httpRequestTimeoutMs)
.build

val dnsNameResolver: DnsNameResolver = new DnsNameResolverBuilder(
new NioEventLoopGroup(1).next()) //We only need 1 thread for DNS resolution
.channelType(classOf[NioDatagramChannel])
.queryTimeoutMillis(configuration.dnsTimeoutMs.toLong)
.maxQueriesPerResolve(2)
.build
val dnsNameResolver: DnsNameResolver =
new DnsNameResolverBuilder(new NioEventLoopGroup(1).next()) //We only need 1 thread for DNS resolution
.channelType(classOf[NioDatagramChannel])
.queryTimeoutMillis(configuration.dnsTimeoutMs.toLong)
.maxQueriesPerResolve(2)
.build

val logger: Logger = LoggerFactory.getLogger("algoliasearch")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ case class MultiQueriesDefinition(

override private[algolia] def build(): HttpPayload = {
val parameters =
strategy.map(s => Some(Map("strategy" -> s.name))).getOrElse(None)
strategy.flatMap(s => Some(Map("strategy" -> s.name)))

HttpPayload(
POST,
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/algolia/objects/Acl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ object Acl {

case object listIndexes extends Acl

case object logs extends Acl

case object seeUnretrievableAttributes extends Acl

}
3 changes: 2 additions & 1 deletion src/main/scala/algolia/objects/QueryRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ case class QueryRules(query: String,
anchoring: Option[String] = None,
context: Option[String] = None,
page: Option[Int] = None,
hitsPerPage: Option[Int] = None)
hitsPerPage: Option[Int] = None,
nbPages: Option[Int] = None)
10 changes: 7 additions & 3 deletions src/main/scala/algolia/responses/BrowseResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@

package algolia.responses

import org.json4s.JObject
import org.json4s.{DefaultFormats, JObject}

case class BrowseResult(cursor: Option[String],
hits: Seq[JObject],
processingTimeMS: Int,
query: String,
params: String) {
params: String,
nbHits: Option[Int],
page: Option[Int],
histPerPage: Option[Int],
nbPages: Option[Int]) {

implicit val formats = org.json4s.DefaultFormats
implicit val formats: DefaultFormats = org.json4s.DefaultFormats

def asHit[T <: Hit: Manifest]: Seq[T] = hits.map(_.extract[T])

Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/algolia/responses/SearchResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ case class SearchResult(hits: Seq[JObject],
facets: Option[Map[String, Map[String, Int]]],
exhaustiveFacetsCount: Option[Boolean],
query: String,
params: String) {
params: String,
// For multiqueries
processed: Option[Boolean],
index: Option[String]) {

implicit val formats: Formats = org.json4s.DefaultFormats

Expand Down Expand Up @@ -74,11 +77,13 @@ trait Hit extends ObjectID {

val _rankingInfo: Option[RankingInfo]

val _distinctSeqID: Option[Integer]

}

case class HighlightResult(value: String, matchLevel: String)

case class SnippetResult(value: String)
case class SnippetResult(value: String, matchLevel: String)

case class RankingInfo(nbTypos: Int,
firstMatchedWord: Int,
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/algolia/responses/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ sealed trait AlgoliaTask {

}

case class Task(taskID: Long, createdAt: Option[String]) extends AlgoliaTask {
case class Task(taskID: Long, createdAt: Option[String] = None, updatedAt: Option[String] = None)
extends AlgoliaTask {
override def idToWaitFor(): Long = taskID
}

case class TasksSingleIndex(taskID: Long, objectIDs: Seq[String], createdAt: Option[String])
case class TasksSingleIndex(taskID: Long, objectIDs: Seq[String], createdAt: Option[String] = None)
extends AlgoliaTask {
override def idToWaitFor(): Long = taskID
}
Expand All @@ -47,7 +48,7 @@ case class TasksMultipleIndex(taskID: Map[String, Long],
override def idToWaitFor(): Long = taskID.values.max
}

case class TaskIndexing(taskID: Long, objectID: String, createdAt: Option[String])
case class TaskIndexing(taskID: Long, objectID: String, createdAt: Option[String] = None)
extends AlgoliaTask {
override def idToWaitFor(): Long = taskID
}
2 changes: 1 addition & 1 deletion src/test/scala/algolia/AlgoliaClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import scala.concurrent.{ExecutionContext, Future}

class AlgoliaClientTest extends AlgoliaTest {

val notSoRandom = new AlgoliaUtils {
val notSoRandom: AlgoliaUtils = new AlgoliaUtils {
override def shuffle(seq: Seq[String]): Seq[String] = seq
}

Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/algolia/dsl/CopyIndexTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CopyIndexTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "toto", "operation"),
body = Some("{\"operation\":\"copy\",\"destination\":\"tata\"}"),
body = Some("""{"operation":"copy","destination":"tata"}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -62,8 +62,7 @@ class CopyIndexTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "toto", "operation"),
body =
Some("{\"operation\":\"copy\",\"destination\":\"tata\",\"scopes\":[\"settings\"]}"),
body = Some("""{"operation":"copy","destination":"tata","scopes":["settings"]}"""),
isSearch = false,
requestOptions = None
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/algolia/dsl/MoveIndexTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MoveIndexTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "toto", "operation"),
body = Some("{\"operation\":\"move\",\"destination\":\"tata\"}"),
body = Some("""{"operation":"move","destination":"tata"}"""),
isSearch = false,
requestOptions = None
)
Expand Down
14 changes: 7 additions & 7 deletions src/test/scala/algolia/dsl/PartialUpdateObjectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
body = Some("{\"toto\":{\"_operation\":\"Increment\",\"value\":1}}"),
body = Some("""{"toto":{"_operation":"Increment","value":1}}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -64,7 +64,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
body = Some("{\"toto\":{\"_operation\":\"Decrement\",\"value\":1}}"),
body = Some("""{"toto":{"_operation":"Decrement","value":1}}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -85,7 +85,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
body = Some("{\"toto\":{\"_operation\":\"Add\",\"value\":\"truc\"}}"),
body = Some("""{"toto":{"_operation":"Add","value":"truc"}}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -106,7 +106,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
body = Some("{\"toto\":{\"_operation\":\"Remove\",\"value\":\"truc\"}}"),
body = Some("""{"toto":{"_operation":"Remove","value":"truc"}}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -127,7 +127,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
body = Some("{\"toto\":{\"_operation\":\"AddUnique\",\"value\":\"truc\"}}"),
body = Some("""{"toto":{"_operation":"AddUnique","value":"truc"}}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -148,7 +148,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
HttpPayload(
POST,
Seq("1", "indexes", "index", "myId", "partial"),
body = Some("{\"toto\":\"truc\"}"),
body = Some("""{"toto":"truc"}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -170,7 +170,7 @@ class PartialUpdateObjectTest extends AlgoliaTest {
POST,
Seq("1", "indexes", "index", "myId", "partial"),
queryParameters = Some(Map("createIfNotExists" -> "false")),
body = Some("{\"toto\":{\"_operation\":\"Increment\",\"value\":1}}"),
body = Some("""{"toto":{"_operation":"Increment","value":1}}"""),
isSearch = false,
requestOptions = None
)
Expand Down
1 change: 0 additions & 1 deletion src/test/scala/algolia/dsl/RulesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ class RulesTest extends AlgoliaTest {
it("should save batches rules of an index") {
save rules Seq(generateRule("rule1")) inIndex "toto" and forwardToSlaves and clearExistingRules
save rules Seq(generateRule("rule2")) inIndex "toto" and forwardToReplicas and clearExistingRules

}

it("should call API") {
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/algolia/dsl/SaveObjectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SaveObjectTest extends AlgoliaTest {
HttpPayload(
POST,
List("1", "indexes", "toto"),
body = Some("{\"name\":\"algolia\",\"age\":2}"),
body = Some("""{"name":"algolia","age":2}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -68,7 +68,7 @@ class SaveObjectTest extends AlgoliaTest {
POST,
List("1", "indexes", "toto", "batch"),
body = Some(
"{\"requests\":[{\"body\":{\"name\":\"algolia\",\"age\":2},\"action\":\"addObject\"}]}"),
"""{"requests":[{"body":{"name":"algolia","age":2},"action":"addObject"}]}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -82,7 +82,7 @@ class SaveObjectTest extends AlgoliaTest {
POST,
List("1", "indexes", "toto", "batch"),
body = Some(
"{\"requests\":[{\"body\":{\"name\":\"algolia\",\"age\":2,\"objectID\":\"id\"},\"action\":\"updateObject\"}]}"),
"""{"requests":[{"body":{"name":"algolia","age":2,"objectID":"id"},"action":"updateObject"}]}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -107,7 +107,7 @@ class SaveObjectTest extends AlgoliaTest {
HttpPayload(
PUT,
List("1", "indexes", "toto", "1"),
body = Some("{\"name\":\"algolia\",\"age\":2}"),
body = Some("""{"name":"algolia","age":2}"""),
isSearch = false,
requestOptions = None
)
Expand All @@ -127,7 +127,7 @@ class SaveObjectTest extends AlgoliaTest {
POST,
List("1", "indexes", "toto", "batch"),
body = Some(
"{\"requests\":[{\"body\":{\"objectID\":\"1\",\"name\":\"algolia\",\"age\":2},\"action\":\"updateObject\"}]}"),
"""{"requests":[{"body":{"objectID":"1","name":"algolia","age":2},"action":"updateObject"}]}"""),
isSearch = false,
requestOptions = None
)
Expand Down
1 change: 0 additions & 1 deletion src/test/scala/algolia/dsl/SynonymsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class SynonymsTest extends AlgoliaTest {
it("should save batches synonyms of an index") {
save synonyms Seq(Placeholder("oid", "1", Seq("2", "3"))) inIndex "toto" and forwardToSlaves and replaceExistingSynonyms
save synonyms Seq(Placeholder("oid", "1", Seq("2", "3"))) inIndex "toto" and forwardToReplicas and replaceExistingSynonyms

}

it("should call API") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class SearchIntegrationTest extends AlgoliaTest {
"563481290",
Some(Map("name" -> HighlightResult("<em>a</em>lgolia", "full"))),
None,
None,
None)
result.asHit[EnhanceTest].head should be(hit)
}
Expand Down Expand Up @@ -235,7 +236,8 @@ case class EnhanceTest(name: String,
objectID: String,
_highlightResult: Option[Map[String, HighlightResult]],
_snippetResult: Option[Map[String, SnippetResult]],
_rankingInfo: Option[RankingInfo])
_rankingInfo: Option[RankingInfo],
_distinctSeqID: Option[Integer])
extends Hit

case class Character(name: String, series: String)

0 comments on commit f6ad92c

Please sign in to comment.