diff --git a/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SearchTest.kt b/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SearchTest.kt index 0787fe99..d44555f5 100644 --- a/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SearchTest.kt +++ b/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SearchTest.kt @@ -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() diff --git a/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/querydsl/search-dsl.kt b/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/querydsl/search-dsl.kt index e2681602..cdf5aff6 100644 --- a/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/querydsl/search-dsl.kt +++ b/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/querydsl/search-dsl.kt @@ -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()