Skip to content
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

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

milicns
Copy link
Contributor

@milicns milicns commented Aug 21, 2023

Part of #64

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Collaborator

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).

Comment on lines 33 to 34
* @param query
* query you wish to run
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

Suggested change
* 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)
Copy link
Collaborator

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
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Comment on lines 188 to 189
extends ConstantScoreQuery[S] { self =>
def boost(value: Double): ConstantScoreQuery[S] =
Copy link
Collaborator

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") {
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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

@milicns milicns requested a review from dbulaja98 August 28, 2023 15:23
@dbulaja98 dbulaja98 merged commit 8b3d2fd into lambdaworks:main Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants