Skip to content

Commit

Permalink
feat(index): rename findFirstObject into findObject
Browse files Browse the repository at this point in the history
[changelog]

Besides the name, the `doNotPaginate` parameter was also turned into
`paginate` so the boolean is easier to read and defaults to true.
  • Loading branch information
aseure committed Aug 29, 2019
1 parent 027c7ec commit 47fbad5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/main/scala/algolia/AlgoliaSyncHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ case class AlgoliaSyncHelper(client: AlgoliaClient) {
}
}

def findFirstObject[T <: ObjectID: Manifest](index: String,
searchQuery: Query,
predicate: T => Boolean,
doNotPaginate: Boolean = false)(
def findObject[T <: ObjectID: Manifest](index: String,
searchQuery: Query,
predicate: T => Boolean,
paginate: Boolean = true)(
implicit duration: Duration,
executor: ExecutionContext): Option[HitsWithPosition[T]] = {
val res = Await.result(client.execute(search into index query searchQuery), duration)
Expand All @@ -103,11 +103,11 @@ case class AlgoliaSyncHelper(client: AlgoliaClient) {
case None => {
val hasNextPage = page + 1 < nbPages

if (doNotPaginate || !hasNextPage) {
if (!paginate || !hasNextPage) {
None
} else {
val newQuery = searchQuery.copy(page = Option(page + 1))
findFirstObject(index, newQuery, predicate, doNotPaginate)
findObject(index, newQuery, predicate, paginate)
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions src/test/scala/algolia/integration/AlgoliaSyncHelperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class AlgoliaSyncHelperTest extends AlgoliaTest {
}

it("should find the first object correctly") {
val indexName = "testFindFirstObject"
val indexName = "testFindObject"

val clearTask = Await.result(helper.client.execute(clear index indexName), Duration.Inf)
Await.result(helper.client.execute(waitFor task clearTask from indexName), Duration.Inf)
Expand All @@ -167,31 +167,31 @@ class AlgoliaSyncHelperTest extends AlgoliaTest {
)
Await.result(helper.client.execute(waitFor task indexingTask from indexName), Duration.Inf)

helper.findFirstObject(indexName, Query(), (_: Employee) => false) should be(None)
helper.findObject(indexName, Query(), (_: Employee) => false) should be(None)

var obj = helper.findFirstObject(indexName, Query(), (_: Employee) => true)
var obj = helper.findObject(indexName, Query(), (_: Employee) => true)
obj should not be (None)
obj.get.page should be(0)
obj.get.position should be(0)

val predicate = (e: Employee) => e.company == "Apple"

helper.findFirstObject(indexName, Query(query = Some("algolia")), predicate) should be(None)

helper.findFirstObject(indexName,
Query(
query = Some(""),
hitsPerPage = Some(5)
),
predicate,
doNotPaginate = true) should be(None)

obj = helper.findFirstObject(indexName,
Query(
query = Some(""),
hitsPerPage = Some(5)
),
predicate)
helper.findObject(indexName, Query(query = Some("algolia")), predicate) should be(None)

helper.findObject(indexName,
Query(
query = Some(""),
hitsPerPage = Some(5)
),
predicate,
paginate = false) should be(None)

obj = helper.findObject(indexName,
Query(
query = Some(""),
hitsPerPage = Some(5)
),
predicate)
obj should not be (None)
obj.get.page should be(2)
obj.get.position should be(0)
Expand Down

0 comments on commit 47fbad5

Please sign in to comment.