diff --git a/docs/overview/queries/elastic_query_boost.md b/docs/overview/queries/elastic_query_boost.md deleted file mode 100644 index 9355e6537..000000000 --- a/docs/overview/queries/elastic_query_boost.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -id: elastic_query_boost -title: "Boosting Query" ---- - -The `Boosting` query returns documents that match the positive query. Among those documents, the ones that also match the negative query get their relevance score lowered by multiplying it by the negative boosting factor. - -In order to use the `Boosting` query import the following: -```scala -import zio.elasticsearch.query.BoostQuery -import zio.elasticsearch.ElasticQuery.boostQuery -``` - -You can create a `Boosting` query using the `boost` method this way: -```scala -val query: BoostQuery = boost(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 `boost` method this way: -```scala -val query: BoostQuery = boost(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). diff --git a/docs/overview/queries/elastic_query_boosting.md b/docs/overview/queries/elastic_query_boosting.md new file mode 100644 index 000000000..0e133ea89 --- /dev/null +++ b/docs/overview/queries/elastic_query_boosting.md @@ -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). diff --git a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala index 3aec09d53..cf8bba476 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala @@ -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. diff --git a/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala b/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala index 5fdaa7a4c..2ce675827 100644 --- a/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala +++ b/modules/library/src/main/scala/zio/elasticsearch/query/Queries.scala @@ -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) diff --git a/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala b/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala index 6a3cb6e53..8c279a3fb 100644 --- a/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala +++ b/modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala @@ -334,13 +334,13 @@ 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) @@ -348,7 +348,7 @@ object ElasticQuerySpec extends ZIOSpecDefault { ) ) && assert(queryTs)( equalTo( - Boost[TestDocument]( + Boosting[TestDocument]( negativeBoost = 0.5f, negativeQuery = exists(TestDocument.stringField), positiveQuery = terms(TestDocument.booleanField, true, false) @@ -2435,9 +2435,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 = """ diff --git a/website/sidebars.js b/website/sidebars.js index 0d5b256dc..1a035f0fb 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -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',