From 88ca363f45c4480cf35e8a291e81a661008ade78 Mon Sep 17 00:00:00 2001 From: Alexander Koval Date: Thu, 4 Jan 2024 19:32:20 +0200 Subject: [PATCH] Add beforeExecute hook for SearchQuery --- elasticmagic/api/elasticmagic.api | 3 ++ .../dev/evo/elasticmagic/SearchQuery.kt | 20 +++++++++- .../evo/elasticmagic/DynamicTemplatesTests.kt | 6 +-- .../dev/evo/elasticmagic/ExplanationTest.kt | 6 +-- .../dev/evo/elasticmagic/ParentChildTests.kt | 14 +++---- .../dev/evo/elasticmagic/SearchQueryTests.kt | 38 +++++++++---------- .../evo/elasticmagic/UpdateMappingTests.kt | 4 +- .../elasticmagic/qf/AttrFacetFilterTests.kt | 14 +++---- .../qf/AttrRangeFacetFilterTests.kt | 2 +- .../elasticmagic/qf/AttrSimpleFiltersTest.kt | 16 ++++---- .../kotlin/samples/bikeshop/Main.kt | 2 +- .../commonMain/kotlin/samples/qf/Process.kt | 4 +- .../commonMain/kotlin/samples/started/Main.kt | 6 +-- 13 files changed, 78 insertions(+), 57 deletions(-) diff --git a/elasticmagic/api/elasticmagic.api b/elasticmagic/api/elasticmagic.api index 627c5cd179..6e4f2957e8 100644 --- a/elasticmagic/api/elasticmagic.api +++ b/elasticmagic/api/elasticmagic.api @@ -27,6 +27,7 @@ public abstract class dev/evo/elasticmagic/BaseSearchQuery { public final fun aggs (Ldev/evo/elasticmagic/SearchQuery$CLEAR;)Ldev/evo/elasticmagic/BaseSearchQuery; public final fun aggs (Ljava/util/Map;)Ldev/evo/elasticmagic/BaseSearchQuery; public final fun aggs ([Lkotlin/Pair;)Ldev/evo/elasticmagic/BaseSearchQuery; + public fun beforeExecute ()V public final fun clone ()Ldev/evo/elasticmagic/BaseSearchQuery; public final fun docvalueFields (Ldev/evo/elasticmagic/SearchQuery$CLEAR;)Ldev/evo/elasticmagic/BaseSearchQuery; public final fun docvalueFields (Ljava/util/List;)Ldev/evo/elasticmagic/BaseSearchQuery; @@ -516,6 +517,8 @@ public class dev/evo/elasticmagic/SearchQuery : dev/evo/elasticmagic/BaseSearchQ public static synthetic fun execute$default (Ldev/evo/elasticmagic/SearchQuery;Ldev/evo/elasticmagic/ElasticsearchIndex;Ljava/util/Map;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public synthetic fun new (Lkotlin/jvm/functions/Function1;)Ldev/evo/elasticmagic/BaseSearchQuery; protected fun new (Lkotlin/jvm/functions/Function1;)Ldev/evo/elasticmagic/SearchQuery; + public final fun search (Ldev/evo/elasticmagic/ElasticsearchIndex;Ljava/util/Map;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static synthetic fun search$default (Ldev/evo/elasticmagic/SearchQuery;Ldev/evo/elasticmagic/ElasticsearchIndex;Ljava/util/Map;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun update (Ldev/evo/elasticmagic/ElasticsearchIndex;Ldev/evo/elasticmagic/query/Script;Ldev/evo/elasticmagic/Refresh;Ldev/evo/elasticmagic/Conflicts;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Map;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun update$default (Ldev/evo/elasticmagic/SearchQuery;Ldev/evo/elasticmagic/ElasticsearchIndex;Ldev/evo/elasticmagic/query/Script;Ldev/evo/elasticmagic/Refresh;Ldev/evo/elasticmagic/Conflicts;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Map;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public final fun updateAsync (Ldev/evo/elasticmagic/ElasticsearchIndex;Ldev/evo/elasticmagic/query/Script;Ldev/evo/elasticmagic/Refresh;Ldev/evo/elasticmagic/Conflicts;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/util/Map;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/SearchQuery.kt b/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/SearchQuery.kt index d04987e0be..7657f6145c 100644 --- a/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/SearchQuery.kt +++ b/elasticmagic/src/commonMain/kotlin/dev/evo/elasticmagic/SearchQuery.kt @@ -689,6 +689,11 @@ abstract class BaseSearchQuery>( params.putNotNullOrRemove("seq_no_primary_term", seqNoPrimaryTerm) } + /** + * Method is called before query execution. Can be overriden in subclasses of [SearchQuery]. + */ + open fun beforeExecute() {} + /** * Makes an immutable view of the search query. Be careful when using this method. * @@ -812,10 +817,19 @@ open class SearchQuery( /** * Executes the search query using an [index]. */ - suspend fun execute(index: ElasticsearchIndex, params: Params? = null): SearchQueryResult { + suspend fun search(index: ElasticsearchIndex, params: Params? = null): SearchQueryResult { + beforeExecute() return index.search(prepareSearch(params)) } + /** + * Alias of [SearchQuery.search]. Executes the search query using an [index]. + */ + @Deprecated("Replaced with `search` method", replaceWith = ReplaceWith("search")) + suspend fun execute(index: ElasticsearchIndex, params: Params? = null): SearchQueryResult { + return search(index, params) + } + /** * Retrieves a number of hits for the search query using an [index]. * @@ -838,6 +852,7 @@ open class SearchQuery( scrollSize: Int? = null, params: Params? = null, ): DeleteByQueryResult { + beforeExecute() return index.deleteByQuery( prepareDelete( Params( @@ -859,6 +874,7 @@ open class SearchQuery( scrollSize: Int? = null, params: Params? = null, ): AsyncResult { + beforeExecute() return index.deleteByQueryAsync( prepareDelete( Params( @@ -886,6 +902,7 @@ open class SearchQuery( scrollSize: Int? = null, params: Params? = null, ): UpdateByQueryResult { + beforeExecute() return index.updateByQuery( prepareUpdate( script, @@ -909,6 +926,7 @@ open class SearchQuery( scrollSize: Int? = null, params: Params? = null, ): AsyncResult { + beforeExecute() return index.updateByQueryAsync( prepareUpdate( script, diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/DynamicTemplatesTests.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/DynamicTemplatesTests.kt index ccf273201d..46b6194a65 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/DynamicTemplatesTests.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/DynamicTemplatesTests.kt @@ -49,17 +49,17 @@ class DynamicTemplatesTests : ElasticsearchTestBase() { // Field does not support fielddata SearchQuery() .sort(companyIdField.id) - .execute(index) + .search(index) } val totalHits = SearchQuery() .filter(companyIdField.id eq "10") - .execute(index) + .search(index) .totalHits totalHits shouldBe 1L val hits = SearchQuery() .sort(companyIdField.asc()) - .execute(index) + .search(index) .hits hits.size shouldBe 2 hits[0].id shouldBe "2" diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ExplanationTest.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ExplanationTest.kt index 1fe6ad2c01..744d0ac465 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ExplanationTest.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ExplanationTest.kt @@ -24,7 +24,7 @@ class ExplanationTest : ElasticsearchTestBase() { fun withoutExplanation() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { val searchQuery = SearchQuery() - val result = searchQuery.execute(index) + val result = searchQuery.search(index) result.totalHits shouldBe 8 result.hits.mapNotNull { it.explanation } shouldBe emptyList() } @@ -34,7 +34,7 @@ class ExplanationTest : ElasticsearchTestBase() { fun withExplanationButEmptySearchQuery() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { val searchQuery = SearchQuery() - val result = searchQuery.execute(index, Params("explain" to true)) + val result = searchQuery.search(index, Params("explain" to true)) result.totalHits shouldBe 8 val explanations = result.hits.mapNotNull { it.explanation } @@ -50,7 +50,7 @@ class ExplanationTest : ElasticsearchTestBase() { fun withExplanation() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { val searchQuery = SearchQuery(StringField("model").match("Galaxy Note 10")) - val result = searchQuery.execute(index, Params("explain" to true)) + val result = searchQuery.search(index, Params("explain" to true)) result.totalHits shouldBe 5 val explanations = result.hits.mapNotNull { it.explanation } diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ParentChildTests.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ParentChildTests.kt index 903975e32d..1a847310db 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ParentChildTests.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ParentChildTests.kt @@ -110,7 +110,7 @@ class ParentChildTests : ElasticsearchTestBase() { "question" to ::QuestionDocSource, "answer" to ::AnswerDocSource ) - SearchQuery(sourceFactory).execute(index).let { searchResult -> + SearchQuery(sourceFactory).search(index).let { searchResult -> searchResult.hits.toSet() shouldContainExactly setOf( SearchHit( index = index.name, @@ -173,7 +173,7 @@ class ParentChildTests : ElasticsearchTestBase() { SearchQuery(sourceFactory) .filter(AnswerDoc.join.eq("answer")) - .execute(index) + .search(index) .let { searchResult -> searchResult.hits.toSet() shouldContainExactly setOf( SearchHit( @@ -225,7 +225,7 @@ class ParentChildTests : ElasticsearchTestBase() { KnowledgeDoc.join.parent("question") ) ) - .execute(index) + .search(index) .let { searchResult -> val parentsAgg = searchResult.agg>("parents") parentsAgg.buckets shouldBe listOf( @@ -236,7 +236,7 @@ class ParentChildTests : ElasticsearchTestBase() { SearchQuery(sourceFactory) .filter(HasParent(QuestionDoc.text.match("What"), "question")) - .execute(index) + .search(index) .let { searchResult -> searchResult.hits.toSet() shouldContainExactly setOf( SearchHit( @@ -260,7 +260,7 @@ class ParentChildTests : ElasticsearchTestBase() { SearchQuery(sourceFactory) .filter(HasChild(MatchAll, "answer", minChildren = 1)) - .execute(index) + .search(index) .let { searchResult -> searchResult.hits.toSet() shouldContainExactly setOf( SearchHit( @@ -284,7 +284,7 @@ class ParentChildTests : ElasticsearchTestBase() { SearchQuery(sourceFactory) .filter(HasChild(MatchAll, "answer", maxChildren = 2)) - .execute(index) + .search(index) .let { searchResult -> searchResult.hits.toSet() shouldContainExactly setOf( SearchHit( @@ -300,7 +300,7 @@ class ParentChildTests : ElasticsearchTestBase() { SearchQuery(sourceFactory) .filter(HasChild(MatchAll, "answer", minChildren = 3)) - .execute(index) + .search(index) .let { searchResult -> searchResult.hits.toSet() shouldContainExactly setOf( SearchHit( diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/SearchQueryTests.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/SearchQueryTests.kt index 4876d218cd..36f4a04446 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/SearchQueryTests.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/SearchQueryTests.kt @@ -236,7 +236,7 @@ class SearchQueryTests : ElasticsearchTestBase() { scriptType = "unknown", ) ) - .execute(index) + .search(index) } } @@ -251,17 +251,17 @@ class SearchQueryTests : ElasticsearchTestBase() { when (val version = cluster.getVersion()) { is Version.Opensearch -> { shouldThrow { - query.execute(index) + query.search(index) } } is Version.Elasticsearch -> { if (version.major < 7) { shouldThrow { - query.execute(index) + query.search(index) } } else { shouldThrow { - query.execute(index) + query.search(index) } } } @@ -275,7 +275,7 @@ class SearchQueryTests : ElasticsearchTestBase() { karlssonsJam, karlssonsBestDonuts, karlssonsJustDonuts, littleBrotherDogStuff )) { val searchResult = SearchQuery(::OrderDocSource) - .execute(index) + .search(index) searchResult.totalHits shouldBe 4 searchResult.maxScore shouldBe 1.0F @@ -289,7 +289,7 @@ class SearchQueryTests : ElasticsearchTestBase() { withFixtures(OrderDoc, listOf(karlssonsJam)) { val searchResult = SearchQuery(::OrderDocSource) .source(excludes=listOf(OrderDoc.comment)) - .execute(index) + .search(index) searchResult.totalHits shouldBe 1 searchResult.maxScore shouldBe 1.0F @@ -308,7 +308,7 @@ class SearchQueryTests : ElasticsearchTestBase() { withFixtures(OrderDoc, listOf(karlssonsJam)) { val searchResult = SearchQuery(::OrderDocSource) .source(false) - .execute(index) + .search(index) searchResult.totalHits shouldBe 1 searchResult.maxScore shouldBe 1.0F @@ -325,7 +325,7 @@ class SearchQueryTests : ElasticsearchTestBase() { val exc = shouldThrow { SearchQuery(::OrderDocSource) .source(OrderDoc.comment) - .execute(index) + .search(index) } exc.message shouldBe "Field [user] is required" } @@ -336,7 +336,7 @@ class SearchQueryTests : ElasticsearchTestBase() { withFixtures(OrderDoc, listOf(karlssonsJam)) { val searchResult = SearchQuery(::OrderDocSource) .docvalueFields(OrderDoc.status, OrderDoc.dateCreated.format("YYYY")) - .execute(index) + .search(index) searchResult.totalHits shouldBe 1 searchResult.maxScore shouldBe 1.0F @@ -358,7 +358,7 @@ class SearchQueryTests : ElasticsearchTestBase() { ::OrderDocSource, OrderDoc.user.id.eq(1) ) - .execute(index) + .search(index) searchResult.totalHits shouldBe 1 searchResult.maxScore shouldBe 1.0F @@ -394,7 +394,7 @@ class SearchQueryTests : ElasticsearchTestBase() { )) { val searchResult = SearchQuery(::OrderDocSource) .filter(OrderDoc.status.eq(OrderStatus.NEW)) - .execute(index) + .search(index) searchResult.totalHits shouldBe 3 searchResult.maxScore.shouldNotBeNull() shouldBe 0.0F @@ -410,7 +410,7 @@ class SearchQueryTests : ElasticsearchTestBase() { )) { val searchResult = SearchQuery(::OrderDocSource) .filter(OrderDoc.dateCreated.lt(LocalDate(2020, 1, 1).atStartOfDayIn(TimeZone.UTC))) - .execute(index) + .search(index) searchResult.totalHits shouldBe 1 searchResult.maxScore.shouldNotBeNull() shouldBe 0.0F @@ -432,7 +432,7 @@ class SearchQueryTests : ElasticsearchTestBase() { )) { val searchResult = SearchQuery(::OrderDocSource) .filter(Ids(listOf("105", "102"))) - .execute(index) + .search(index) searchResult.totalHits shouldBe 2 searchResult.maxScore shouldBe 0.0F @@ -459,7 +459,7 @@ class SearchQueryTests : ElasticsearchTestBase() { order = Sort.Order.DESC, ) ) - .execute(index) + .search(index) searchResult.totalHits shouldBe 4 searchResult.maxScore shouldBe null @@ -487,7 +487,7 @@ class SearchQueryTests : ElasticsearchTestBase() { nested = Sort.Nested(OrderDoc.items) ) ) - .execute(index) + .search(index) searchResult.totalHits shouldBe 4 searchResult.maxScore shouldBe null @@ -513,7 +513,7 @@ class SearchQueryTests : ElasticsearchTestBase() { ), ) .size(0) - .execute(index) + .search(index) searchResult.totalHits shouldBe 4 // Elasticsearch 6.x has max score 0.0, but 7.x has null @@ -551,7 +551,7 @@ class SearchQueryTests : ElasticsearchTestBase() { ), ) .size(0) - .execute(index) + .search(index) val ordersByYear = searchResult.agg>("orders_by_year") ordersByYear.buckets.shouldHaveSize(3) @@ -589,7 +589,7 @@ class SearchQueryTests : ElasticsearchTestBase() { ) ) .size(0) - .execute(index) + .search(index) searchResult.totalHits shouldBe 4 searchResult.maxScore ?: 0.0 shouldBe 0.0 @@ -649,7 +649,7 @@ class SearchQueryTests : ElasticsearchTestBase() { .aggs("days_of_week" to TermsAgg(dayOfWeekField)) .fields(dayOfWeekField, statusStrField) .sort(dayOfWeekField) - .execute(index) + .search(index) searchResult.hits.size shouldBe 4 searchResult.hits.flatMap { hit -> hit.fields[dayOfWeekField] } shouldBe listOf( diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/UpdateMappingTests.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/UpdateMappingTests.kt index 1cdcca4ceb..3b8367d8ac 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/UpdateMappingTests.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/UpdateMappingTests.kt @@ -44,7 +44,7 @@ class UpdateMappingTests : ElasticsearchTestBase() { SearchQuery( ::UserDocSource, UserV2Doc.name.match("boy") ) - .execute(index) + .search(index) .totalHits shouldBe 0 cluster.updateMapping( @@ -63,7 +63,7 @@ class UpdateMappingTests : ElasticsearchTestBase() { SearchQuery( ::UserDocSource, UserV2Doc.name.match("boy") ) - .execute(index) + .search(index) .totalHits shouldBe 1 } } diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrFacetFilterTests.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrFacetFilterTests.kt index c0bf1a26d6..29199fc31c 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrFacetFilterTests.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrFacetFilterTests.kt @@ -30,13 +30,13 @@ class AttrFacetFilterTests : ElasticsearchTestBase() { fun facet() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { var searchQuery = SearchQuery() - searchQuery.execute(index).totalHits shouldBe 8 + searchQuery.search(index).totalHits shouldBe 8 searchQuery = SearchQuery() ItemQueryFilters.apply( searchQuery, emptyMap() ).let { appliedFilters -> - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 8 val qfResult = appliedFilters.processResult(searchResult) @@ -141,7 +141,7 @@ class AttrFacetFilterTests : ElasticsearchTestBase() { ItemQueryFilters.apply( searchQuery, mapOf(listOf("attr", Manufacturer.ATTR_ID.toString()) to listOf("0")) ).let { appliedFilters -> - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 3 val qfResult = appliedFilters.processResult(searchResult) @@ -223,7 +223,7 @@ class AttrFacetFilterTests : ElasticsearchTestBase() { listOf("attr", "3") to listOf("12"), ) ).let { appliedFilters -> - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 2 val qfResult = appliedFilters.processResult(searchResult) @@ -301,7 +301,7 @@ class AttrFacetFilterTests : ElasticsearchTestBase() { listOf("attr", "5", "gte") to listOf("6.5"), ) ).let { appliedFilters -> - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 0 val qfResult = appliedFilters.processResult(searchResult) @@ -349,7 +349,7 @@ class AttrFacetFilterTests : ElasticsearchTestBase() { listOf("attr", "6", "lte") to listOf("5000"), ) ).let { appliedFilters -> - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 3 val qfResult = appliedFilters.processResult(searchResult) @@ -431,7 +431,7 @@ class AttrFacetFilterTests : ElasticsearchTestBase() { listOf("attr", "4", "all") to listOf("1", "3"), ) ).let { appliedFilters -> - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 2 val qfResult = appliedFilters.processResult(searchResult) diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrRangeFacetFilterTests.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrRangeFacetFilterTests.kt index 98f877a3f5..e0186563b5 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrRangeFacetFilterTests.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrRangeFacetFilterTests.kt @@ -57,7 +57,7 @@ class AttrRangeFacetFilterTests : ElasticsearchTestBase() { fun rangeQueries() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES, cleanup = false) { val searchQuery = SearchQuery() - searchQuery.execute(index).totalHits shouldBe 55 + searchQuery.search(index).totalHits shouldBe 55 testRangeFiltering( SelectedValue.Gte(ATTR_ID, Float.NEGATIVE_INFINITY), diff --git a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrSimpleFiltersTest.kt b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrSimpleFiltersTest.kt index 64914c6992..05b741c047 100644 --- a/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrSimpleFiltersTest.kt +++ b/integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/qf/AttrSimpleFiltersTest.kt @@ -18,14 +18,14 @@ class AttrSimpleFiltersTest : ElasticsearchTestBase() { fun attrSimpleFilterTest() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { val searchQuery = SearchQuery() - val result = searchQuery.execute(index) + val result = searchQuery.search(index) result.totalHits shouldBe 8 ItemQueryFilters.apply( searchQuery, mapOf(listOf("attr", Manufacturer.ATTR_ID.toString(), "any") to listOf("1", "0")) ).let { - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 4 } } @@ -35,13 +35,13 @@ class AttrSimpleFiltersTest : ElasticsearchTestBase() { fun attrBoolSimpleFilterTest() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { val searchQuery = SearchQuery() - searchQuery.execute(index).totalHits shouldBe 8 + searchQuery.search(index).totalHits shouldBe 8 ItemQueryFilters.apply( searchQuery, mapOf(listOf("attr", ExtensionSlot.ATTR_ID.toString()) to listOf("true")) ).let { - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 3 } } @@ -51,13 +51,13 @@ class AttrSimpleFiltersTest : ElasticsearchTestBase() { fun attrRangeSimpleFilterTest() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { val searchQuery = SearchQuery() - searchQuery.execute(index).totalHits shouldBe 8 + searchQuery.search(index).totalHits shouldBe 8 ItemQueryFilters.apply( searchQuery, mapOf(listOf("attr", DisplaySize.ATTR_ID.toString(), "gte") to listOf("6.7")) ).let { - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 3 } } @@ -67,7 +67,7 @@ class AttrSimpleFiltersTest : ElasticsearchTestBase() { fun applyAllSimpleFilters() = runTestWithSerdes { withFixtures(ItemDoc, FIXTURES) { val searchQuery = SearchQuery() - searchQuery.execute(index).totalHits shouldBe 8 + searchQuery.search(index).totalHits shouldBe 8 ItemQueryFilters.apply( searchQuery, @@ -77,7 +77,7 @@ class AttrSimpleFiltersTest : ElasticsearchTestBase() { listOf("attr", DisplaySize.ATTR_ID.toString(), "gte") to listOf("6.3"), ) ).let { - val searchResult = searchQuery.execute(index) + val searchResult = searchQuery.search(index) searchResult.totalHits shouldBe 2 val qfResult = it.processResult(searchResult) diff --git a/samples/src/commonMain/kotlin/samples/bikeshop/Main.kt b/samples/src/commonMain/kotlin/samples/bikeshop/Main.kt index 656729ca2e..ef032ef897 100644 --- a/samples/src/commonMain/kotlin/samples/bikeshop/Main.kt +++ b/samples/src/commonMain/kotlin/samples/bikeshop/Main.kt @@ -34,7 +34,7 @@ fun main() = runBlocking { println("Query filter params: $qfParams") val searchQuery = SearchQuery(::BikeDocSource) val appliedFilters = BikeShopQueryFilters.apply(searchQuery, qfParams) - val searchResult = searchQuery.execute(bikeShopIndex) + val searchResult = searchQuery.search(bikeShopIndex) val qfResult = appliedFilters.processResult(searchResult) diff --git a/samples/src/commonMain/kotlin/samples/qf/Process.kt b/samples/src/commonMain/kotlin/samples/qf/Process.kt index 1ddaa2c3c1..4f094dc870 100644 --- a/samples/src/commonMain/kotlin/samples/qf/Process.kt +++ b/samples/src/commonMain/kotlin/samples/qf/Process.kt @@ -5,7 +5,7 @@ import samples.started.cluster suspend fun process() { val filtersResult = appliedFilters.processResult( - searchQuery.execute(cluster["elasticmagic-samples_bike"]) + searchQuery.search(cluster["elasticmagic-samples_bike"]) ) val manufacturerFacet = filtersResult[BikeQueryFilters.manufacturer] @@ -35,4 +35,4 @@ suspend fun process() { println("Current page: ${page.page}") println("Total pages: ${page.totalPages}") println() -} \ No newline at end of file +} diff --git a/samples/src/commonMain/kotlin/samples/started/Main.kt b/samples/src/commonMain/kotlin/samples/started/Main.kt index 48257a9dd2..0f175b0298 100644 --- a/samples/src/commonMain/kotlin/samples/started/Main.kt +++ b/samples/src/commonMain/kotlin/samples/started/Main.kt @@ -31,17 +31,17 @@ fun main() = runBlocking { // Find all users val sq = SearchQuery() - printUsers(sq.execute(userIndex)) + printUsers(sq.search(userIndex)) // Find nobody users sq.query(UserDoc.about.match("nobody")) - printUsers(sq.execute(userIndex)) + printUsers(sq.search(userIndex)) // Build an aggregation that counts users inside a group printGroupsAgg( SearchQuery() .aggs("groups" to TermsAgg(UserDoc.groups)) - .execute(userIndex) + .search(userIndex) .agg("groups") ) }