-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from UsenkoArtem/add_explain_result_to_hits
Add explanation to hits
- Loading branch information
Showing
7 changed files
with
131 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/ExplanationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dev.evo.elasticmagic | ||
|
||
import dev.evo.elasticmagic.doc.BoundField | ||
import dev.evo.elasticmagic.doc.RootFieldSet | ||
import dev.evo.elasticmagic.qf.FIXTURES | ||
import dev.evo.elasticmagic.qf.ItemDoc | ||
import dev.evo.elasticmagic.query.match | ||
import dev.evo.elasticmagic.types.TextType | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.shouldNotBe | ||
import kotlin.test.Test | ||
|
||
class ExplanationTest : ElasticsearchTestBase() { | ||
override val indexName = "explanation" | ||
|
||
class StringField(name: String) : BoundField<String, String>( | ||
name, | ||
TextType, | ||
Params(), | ||
RootFieldSet | ||
) | ||
|
||
@Test | ||
fun withoutExplanation() = runTestWithSerdes { | ||
withFixtures(ItemDoc, FIXTURES) { | ||
val searchQuery = SearchQuery() | ||
val result = searchQuery.execute(index) | ||
result.totalHits shouldBe 8 | ||
result.hits.mapNotNull { it.explanation } shouldBe emptyList() | ||
} | ||
} | ||
|
||
@Test | ||
fun withExplanationButEmptySearchQuery() = runTestWithSerdes { | ||
withFixtures(ItemDoc, FIXTURES) { | ||
val searchQuery = SearchQuery() | ||
val result = searchQuery.execute(index, Params("explain" to true)) | ||
result.totalHits shouldBe 8 | ||
val explanations = result.hits.mapNotNull { it.explanation } | ||
|
||
explanations.size shouldBe 8 | ||
explanations.map { | ||
it.value shouldNotBe 1.0f | ||
it.details shouldBe emptyList() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun withExplanation() = runTestWithSerdes { | ||
withFixtures(ItemDoc, FIXTURES) { | ||
val searchQuery = SearchQuery(StringField("model").match("Galaxy Note 10")) | ||
val result = searchQuery.execute(index, Params("explain" to true)) | ||
result.totalHits shouldBe 5 | ||
val explanations = result.hits.mapNotNull { it.explanation } | ||
|
||
explanations.size shouldBe 5 | ||
explanations.map { | ||
it.description shouldBe "sum of:" | ||
it.details.size shouldNotBe 0 | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters