Skip to content

Commit

Permalink
Merge pull request #136 from AnyRoad/match_all_match_none
Browse files Browse the repository at this point in the history
adds match_none query and boost parameter for the match_all query
  • Loading branch information
jillesvangurp authored May 8, 2024
2 parents c95bcf6 + 23f6f78 commit 15955eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ class SearchTest : SearchTestBase() {
}.total shouldBe 2
}

@Test
fun shouldReturnAllDocumentsWithMatchAll() = coRun {
val index = testDocumentIndex()
client.indexDocument(index, TestDocument("foo bar").json(false), refresh = Refresh.WaitFor, id = "1")
client.indexDocument(index, TestDocument("fooo").json(false), refresh = Refresh.WaitFor, id = "2")
client.indexDocument(index, TestDocument("bar").json(false), refresh = Refresh.WaitFor, id = "3")

val result = client.search("$index,$index") {
query = matchAll(boost = 3.5)
}
result.hits!!.hits shouldHaveSize 3
result.hits!!.hits.map(SearchResponse.Hit::score) shouldBe listOf(3.5, 3.5, 3.5)
}

@Test
fun shouldReturnEmptyResultWithMatchNone() = coRun {
val index = testDocumentIndex()
client.indexDocument(index, TestDocument("foo bar").json(false), refresh = Refresh.WaitFor, id = "1")
client.indexDocument(index, TestDocument("fooo").json(false), refresh = Refresh.WaitFor, id = "2")
client.indexDocument(index, TestDocument("bar").json(false), refresh = Refresh.WaitFor, id = "3")

val result = client.search("$index,$index") {
query = matchNone()
}
result.total shouldBe 0
result.hits!!.hits shouldHaveSize 0
}

@Test
fun shouldDoScrollingSearch() = coRun {
val index = testDocumentIndex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ fun Collapse.InnerHits.collapse(field: String, block: (Collapse.() -> Unit)? = n

fun Collapse.InnerHits.collapse(field: KProperty<*>, block: (Collapse.() -> Unit)? = null) = collapse(field.name, block)

fun QueryClauses.matchAll() = ESQuery("match_all")
fun QueryClauses.matchAll(boost: Double? = null) = ESQuery("match_all").apply {
boost?.let { this["boost"] = boost }
}
fun QueryClauses.matchNone() = ESQuery("match_none")

class Script : JsonDsl() {
var source by property<String>()
Expand Down

0 comments on commit 15955eb

Please sign in to comment.