-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(dsl): Support Terms set
query
#355
(dsl): Support Terms set
query
#355
Conversation
Terms set
query
title: "Terms Set Query" | ||
--- | ||
|
||
The `TermsSet` query returns documents that contain the minimum amount of exact terms in a provided field. The terms set query is the same as [[zio.elasticsearch.query.TermsQuery]], except you can define the number of matching terms required to return a document. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `TermsSet` query returns documents that contain the minimum amount of exact terms in a provided field. The terms set query is the same as [[zio.elasticsearch.query.TermsQuery]], except you can define the number of matching terms required to return a document. | |
The `TermsSet` query returns documents that contain the minimum amount of exact terms in a provided field. The Terms set query is the same as [[zio.elasticsearch.query.TermsQuery]], except you can define the number of matching terms required to return a document. |
@@ -936,7 +936,7 @@ object ElasticQuery { | |||
* @tparam A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put A
before S
in scaladoc?
final def termsSet[S, A: ElasticPrimitive]( | ||
field: Field[S, A], | ||
minimumShouldMatchField: String, | ||
terms: A* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can there be zero terms?
*/ | ||
final def termsSetScript[A: ElasticPrimitive]( | ||
field: String, | ||
minimumShouldMatchScript: zio.elasticsearch.script.Script, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why with prefix?
@@ -1477,7 +1551,7 @@ object HttpExecutorSpec extends IntegrationSpec { | |||
Executor.execute(ElasticRequest.createIndex(firstSearchIndex)), | |||
Executor.execute(ElasticRequest.deleteIndex(firstSearchIndex)).orDie | |||
), | |||
test("search for a document using script query") { | |||
test("search for a document using should without satisfying minimumShouldMatch condition") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you omit: without satisfying minimumShouldMatch condition
? If that makes sense.
@@ -1342,6 +1342,80 @@ object HttpExecutorSpec extends IntegrationSpec { | |||
Executor.execute(ElasticRequest.createIndex(firstSearchIndex)), | |||
Executor.execute(ElasticRequest.deleteIndex(firstSearchIndex)).orDie | |||
), | |||
test("search for a document using a terms set query with minimumShouldMatchField") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put 2 in intField, and make one of them not passing the check.
Executor.execute(ElasticRequest.createIndex(firstSearchIndex)), | ||
Executor.execute(ElasticRequest.deleteIndex(firstSearchIndex)).orDie | ||
), | ||
test("search for a document using a terms set query with minimumShouldMatchScript") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
|
||
You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `TermsSet` query with defined `minimumShouldMatchField` using the `termsSet` method this way: | ||
```scala | ||
val query: TermsSetQuery = termsSet(field = Document.name, minimumShouldMatchField = "intField", terms = 1, 2, 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if minimumShouldMatchField
can be type-safe too.
```scala | ||
val query: TermsSetQuery = termsSetScript(field = "stringField", minimumShouldMatchScript = Script("doc['intField'].value"), terms = 1, 2, 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put Script
import here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also because of stringField, consider changing 1,2,3 to something else (everywhere here)
val query: TermsSetQuery = termsSet(field = Document.name, minimumShouldMatchField = Document.field, terms = "a", "b", "c") | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val query: TermsSetQuery = termsSet(field = Document.name, minimumShouldMatchField = Document.field, terms = "a", "b", "c") | |
``` | |
val query: TermsSetQuery = termsSet(field = Document.name, minimumShouldMatchField = Document.intField, terms = "a", "b", "c") |
terms = Chunk.fromIterable(terms), | ||
minimumShouldMatchField = Some(minimumShouldMatchField), | ||
minimumShouldMatchScript = None, | ||
boost = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put boost
before minimumShouldMatchField
and minimumShouldMatchScript
.
terms: Chunk[A], | ||
minimumShouldMatchField: Option[String], | ||
minimumShouldMatchScript: Option[zio.elasticsearch.script.Script], | ||
boost: Option[Double] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put boost
before minimumShouldMatchField
an minimumShouldMatchScript
.
val queryWithBoost: TermsSetQuery = termsSet(field = "booleanField", minimumShouldMatchField = "intField", terms = true, false).boost(2.0) | ||
val queryWithBoost: TermsSetQuery = termsSetScript(field = "booleanField", minimumShouldMatchScript = Script("doc['intField'].value"), terms = true, false).boost(2.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give them different names.
terms = "a", | ||
"b", | ||
"c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put this all in the same line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question for every situation like this in new tests you have added.
terms = "a", | ||
"b", | ||
"c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put this all in the same line?
7a42c09
to
8b4906e
Compare
8b4906e
to
c5f9916
Compare
Part of #91