-
Notifications
You must be signed in to change notification settings - Fork 18
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 constantScore
query
#307
(dsl): Support constantScore
query
#307
Conversation
val query: ConstantScoreQuery = constantScore(matchPhrase(field = "name", value = "test")) | ||
``` | ||
|
||
You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `ConstantScore` query with arbitrary query(`MatchPhrase` in this example) using the `constantScore` method in the following manner: |
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.
You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `ConstantScore` query with arbitrary query(`MatchPhrase` in this example) using the `constantScore` method in the following manner: | |
You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `ConstantScore` query with arbitrary [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) query(`MatchPhrase` in this example) using the `constantScore` method in the following manner: |
|
||
If you want to change the `boost`, you can use `boost` method: | ||
```scala | ||
val queryWithBoost: ConstantScoreQuery = constantScore(matchPhrase(field = Document.name, value ="test")).boost(2.2) |
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 queryWithBoost: ConstantScoreQuery = constantScore(matchPhrase(field = Document.name, value ="test")).boost(2.2) | |
val queryWithBoost: ConstantScoreQuery = constantScore(matchPhrase(field = Document.name, value = "test")).boost(2.2) |
) | ||
).boost(2.1) | ||
res <- Executor.execute(ElasticRequest.search(firstSearchIndex, query)).documentAs[TestDocument] | ||
} yield assert(res)(Assertion.contains(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.
Add if possible: assert(res)(!Assertion.contains(secondDocumentId)
.
* @param query | ||
* query you wish to run |
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 something like this:
query to be wrapped inside of constant score query? Or something similar.
* @param query | ||
* query you wish to run | ||
* @tparam S | ||
* document for which field query is executed. An implicit `Schema` instance must be in scope |
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
* document for which field query is executed. An implicit `Schema` instance must be in scope | |
* document for which field query is specified for. An implicit `Schema` instance must be in scope | |
```? |
* that must satisfy the criteria. | ||
*/ | ||
final def constantScore(query: ElasticQuery[Any]): ConstantScoreQuery[Any] = | ||
ConstantScore[Any](query, 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.
Name first parameter.
* relevance score equal to the boost parameter value. | ||
* | ||
* @param query | ||
* query you wish to run |
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 as above.
* query you wish to run | ||
* @return | ||
* an instance of [[zio.elasticsearch.query.ConstantScoreQuery]] that represents the constant score query with query | ||
* that must satisfy the criteria. |
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 as above.
extends ConstantScoreQuery[S] { self => | ||
def boost(value: Double): ConstantScoreQuery[S] = |
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 empty line between.
@@ -1873,6 +1903,41 @@ object ElasticQuerySpec extends ZIOSpecDefault { | |||
assert(queryWithAllParams.toJson(fieldPath = None))(equalTo(expectedWithAllParams.toJson)) | |||
} | |||
), | |||
test("constantScore") { |
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.
Some parameters are named, some are not.
* @param query | ||
* query to be wrapped inside of constant score query | ||
* @tparam S | ||
* document for which field query is specified for. An implicit `Schema` instance must be in scope |
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.
* document for which field query is specified for. An implicit `Schema` instance must be in scope | |
* document for which field query is specified for. An implicit `Schema` instance must be provided in the scope |
Part of #64