Skip to content

Commit

Permalink
Fix code remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjaftn committed Nov 17, 2023
1 parent 0afc2a5 commit 8704dc9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 53 deletions.
24 changes: 0 additions & 24 deletions docs/overview/queries/elastic_query_boost.md

This file was deleted.

24 changes: 24 additions & 0 deletions docs/overview/queries/elastic_query_boosting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
id: elastic_query_boosting
title: "Boosting Query"
---

The `Boosting` query returns documents that match the query marked as `positive` while reducing the relevance score of documents that also match a query which is marked as `negative` query.

In order to use the `Boosting` query import the following:
```scala
import zio.elasticsearch.query.BoostingQuery
import zio.elasticsearch.ElasticQuery.boostingQuery
```

You can create a `Boosting` query using the `boosting` method this way:
```scala
val query: BoostingQuery = boosting(negativeBoost = 0.5f, negativeQuery = contains(field = "testField", value = "a"), positiveQuery = startsWith(field = "testId", value = "b"))
```

You can create a [type-safe](https://lambdaworks.github.io/zio-elasticsearch/overview/overview_zio_prelude_schema) `Boosting` query using the `boosting` method this way:
```scala
val query: BoostingQuery = boosting(negativeBoost = 0.5f, negativeQuery = contains(field = Document.stringField, value = "a"), positiveQuery = startsWith(field = Document.id, value = "b"))
```

You can find more information about `Boosting` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html#boosting-query-ex-request).
34 changes: 17 additions & 17 deletions modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,46 @@ import zio.schema.Schema
object ElasticQuery {

/**
* Constructs a type-safe instance of [[zio.elasticsearch.query.BoostQuery]] with queries that must satisfy the
* Constructs a type-safe instance of [[zio.elasticsearch.query.BoostingQuery]] with queries that must satisfy the
* criteria using the specified parameters.
*
* @param negativeBoost
* the query that decreases the relevance score of matching documents.
* the number between 0 and 1.0 used to decrease the relevance score of documents matching the negative query
* @param negativeQuery
* the query that decreases the relevance score of matching documents.
* the query that decreases the relevance score of matching documents
* @param positiveQuery
* the query that must be satisfied.
* the query that must be satisfied
* @tparam S
* document for which field query is executed. An implicit `Schema` instance must be in scope.
* document for which field query is executed. An implicit `Schema` instance must be in scope
* @return
* an instance of [[zio.elasticsearch.query.BoostQuery]] that represents the boost query to be performed.
* an instance of [[zio.elasticsearch.query.BoostingQuery]] that represents the boost query to be performed
*/
final def boost[S: Schema](
final def boosting[S: Schema](
negativeBoost: Float,
negativeQuery: ElasticQuery[S],
positiveQuery: ElasticQuery[S]
): BoostQuery[S] =
Boost(negativeBoost = negativeBoost, negativeQuery = negativeQuery, positiveQuery = positiveQuery)
): BoostingQuery[S] =
Boosting(negativeBoost = negativeBoost, negativeQuery = negativeQuery, positiveQuery = positiveQuery)

/**
* Constructs an instance of [[zio.elasticsearch.query.BoostQuery]] with queries that must satisfy the criteria using
* Constructs an instance of [[zio.elasticsearch.query.BoostingQuery]] with queries that must satisfy the criteria using
* the specified parameters.
*
* @param negativeBoost
* the query that decreases the relevance score of matching documents.
* the number between 0 and 1.0 used to decrease the relevance score of documents matching the negative query
* @param negativeQuery
* the query that decreases the relevance score of matching documents.
* the query that decreases the relevance score of matching documents
* @param positiveQuery
* the query that must be satisfied.
* the query that must be satisfied
* @return
* an instance of [[zio.elasticsearch.query.BoostQuery]] that represents the boost query to be performed.
* an instance of [[zio.elasticsearch.query.BoostingQuery]] that represents the boost query to be performed
*/
final def boost(
final def boosting(
negativeBoost: Float,
negativeQuery: ElasticQuery[Any],
positiveQuery: ElasticQuery[Any]
): BoostQuery[Any] =
Boost(negativeBoost = negativeBoost, negativeQuery = negativeQuery, positiveQuery = positiveQuery)
): BoostingQuery[Any] =
Boosting(negativeBoost = negativeBoost, negativeQuery = negativeQuery, positiveQuery = positiveQuery)

/**
* Constructs a type-safe instance of [[zio.elasticsearch.query.ConstantScoreQuery]] with a specified query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ private[elasticsearch] final case class Bool[S](
}
}

sealed trait BoostQuery[S] extends ElasticQuery[S]
sealed trait BoostingQuery[S] extends ElasticQuery[S]

private[elasticsearch] final case class Boost[S](
private[elasticsearch] final case class Boosting[S](
negativeBoost: Float,
negativeQuery: ElasticQuery[S],
positiveQuery: ElasticQuery[S]
) extends BoostQuery[S] { self =>
) extends BoostingQuery[S] { self =>

private[elasticsearch] def toJson(fieldPath: Option[String]): Json = {
val negativeBoostJson = Obj("negative_boost" -> negativeBoost.toJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,21 @@ object ElasticQuerySpec extends ZIOSpecDefault {
)
}
),
test("boost") {
val query = boost(0.5f, exists("testField"), terms("booleanField", true, false))
val queryTs = boost(0.5f, exists(TestDocument.stringField), terms(TestDocument.booleanField, true, false))
test("boosting") {
val query = boosting(0.5f, exists("testField"), terms("booleanField", true, false))
val queryTs = boosting(0.5f, exists(TestDocument.stringField), terms(TestDocument.booleanField, true, false))

assert(query)(
equalTo(
Boost[Any](
Boosting[Any](
negativeBoost = 0.5f,
negativeQuery = exists("testField"),
positiveQuery = terms("booleanField", true, false)
)
)
) && assert(queryTs)(
equalTo(
Boost[TestDocument](
Boosting[TestDocument](
negativeBoost = 0.5f,
negativeQuery = exists(TestDocument.stringField),
positiveQuery = terms(TestDocument.booleanField, true, false)
Expand Down Expand Up @@ -2168,9 +2168,9 @@ object ElasticQuerySpec extends ZIOSpecDefault {
assert(queryWithAllParams.toJson(fieldPath = None))(equalTo(expectedWithAllParams.toJson))
}
),
test("boost") {
val query = boost(0.5f, exists("stringField"), terms("booleanField", true, false))
val queryTs = boost(0.5f, exists(TestDocument.stringField), terms(TestDocument.booleanField, true, false))
test("boosting") {
val query = boosting(0.5f, exists("stringField"), terms("booleanField", true, false))
val queryTs = boosting(0.5f, exists(TestDocument.stringField), terms(TestDocument.booleanField, true, false))

val expected =
"""
Expand Down
2 changes: 1 addition & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
items: [
'overview/elastic_query',
'overview/queries/elastic_query_bool',
'overview/queries/elastic_query_boost',
'overview/queries/elastic_query_boosting',
'overview/queries/elastic_query_constant_score',
'overview/queries/elastic_query_exists',
'overview/queries/elastic_query_function_score',
Expand Down

0 comments on commit 8704dc9

Please sign in to comment.