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 13, 2023
1 parent 73db9b2 commit f04af37
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 42 deletions.
6 changes: 3 additions & 3 deletions docs/overview/queries/elastic_query_disjunction_max.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: elastic_query_disjunction_max
title: "Disjunction max Query"
---

The `Disjunction max` query returns documents that match one or more query clauses. For documents that match multiple query clauses, the relevance score is set to the highest relevance score from all matching query clauses. When the relevance scores of the returned documents are identical, tie breaker parameter gives more weight to documents that match multiple query clauses.
The `Disjunction max` query returns documents that match one or more query clauses. For documents that match multiple query clauses, the relevance score is set to the highest relevance score from all matching query clauses. When the relevance scores of the returned documents are identical, tie breaker parameter can be used for giving more weight to documents that match multiple query clauses.

In order to use the `Disjunction max` query import the following:
```scala
Expand All @@ -13,12 +13,12 @@ import zio.elasticsearch.ElasticQuery.disjunctionMax

You can create a `Disjunction max` query using the `disjunctionMax` method this way:
```scala
val query: DisjunctionMaxQuery = disjunctionMax( queries = Chunk( term( field = "stringField", value = "test"), exists( field = "intField")))
val query: DisjunctionMaxQuery = disjunctionMax(queries = Chunk(term(field = "stringField", value = "test"), exists( field = "intField")))
```

If you want to change the `tieBreaker`, you can use `tieBreaker` method:
```scala
val queryWithPrefixLength: DisjunctionMaxQuery = disjunctionMax( queries = Chunk( queries = Chunk( exists("existsField"), ids("1", "2", "3"))).tieBreaker(0.5f))
val queryWithPrefixLength: DisjunctionMaxQuery = disjunctionMax(queries = Chunk(exists("existsField"), ids("1", "2", "3"))).tieBreaker(0.5f)
```

You can find more information about `Disjunction max` query [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,16 +1080,16 @@ object HttpExecutorSpec extends IntegrationSpec {
Executor.execute(ElasticRequest.createIndex(firstSearchIndex)),
Executor.execute(ElasticRequest.deleteIndex(firstSearchIndex)).orDie
),
test("search for a document using a disjunction max query ttt") {
test("search for a document using a disjunction max query") {
checkOnce(genDocumentId, genTestDocument, genDocumentId, genTestDocument) {
(firstDocumentId, firstDocument, secondDocumentId, secondDocument) =>
for {
_ <- Executor.execute(ElasticRequest.deleteByQuery(firstSearchIndex, matchAll))
firstDocumentUpdated =
firstDocument.copy(stringField = s"this is a ${firstDocument.stringField} test.")
firstDocument.copy(stringField = s"This is a ${firstDocument.stringField} test.")
secondDocumentUpdated =
secondDocument.copy(stringField =
s"this is not a ${firstDocument.stringField} test. It is a ${secondDocument.stringField} test, but not ${firstDocument.stringField}"
s"This is a ${secondDocument.stringField} test. It should be in the list before ${firstDocument.stringField}, because it has higher relevance score than ${firstDocument.stringField}"
)
_ <- Executor.execute(
ElasticRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,30 @@ object ElasticQuery {
Wildcard(field = field, value = s"*$value*", boost = None, caseInsensitive = None)

/**
* Constructs an instance of [[zio.elasticsearch.query.DisjunctionMax]] using the specified parameters.
* Constructs a type-safe instance of [[zio.elasticsearch.query.DisjunctionMax]] using the specified parameters.
*
* @param queries
* the type-safe [[ElasticQuery]] object to be wrapped inside of disjunction max query
* the type-safe [[ElasticQuery]] objects to be wrapped inside of disjunction max query
* @tparam S
* document for which field query is executed
* document for which field query is executed. An implicit `Schema` instance must be in scope
* @return
* an instance of [[zio.elasticsearch.query.DisjunctionMax]] that represents the `disjunction max` query to be
* performed.
*/
final def disjunctionMax[S: Schema](queries: Chunk[ElasticQuery[S]]): DisjunctionMaxQuery[S] =
DisjunctionMax[S](queries = queries, tieBreaker = None)

/**
* Constructs an instance of [[zio.elasticsearch.query.DisjunctionMax]] using the specified parameters.
*
* @param queries
* the [[ElasticQuery]] objects to be wrapped inside of disjunction max query
* @return
* an instance of [[zio.elasticsearch.query.DisjunctionMax]] that represents the `disjunction max` query to be
* performed.
*/
final def disjunctionMax[S](queries: Chunk[ElasticQuery[S]]): DisjunctionMaxQuery[S] =
DisjunctionMax(queries = queries, tieBreaker = None)
final def disjunctionMax(queries: Chunk[ElasticQuery[Any]]): DisjunctionMaxQuery[Any] =
DisjunctionMax[Any](queries = queries, tieBreaker = None)

/**
* Constructs a type-safe instance of [[zio.elasticsearch.query.ExistsQuery]], that checks existence of the field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,30 +202,6 @@ private[elasticsearch] final case class ConstantScore[S](query: ElasticQuery[S],

sealed trait DisjunctionMaxQuery[S] extends ElasticQuery[S] {

/**
* Adds specified queries to the [[zio.elasticsearch.query.DisjunctionMaxQuery]]. Returned documents must match one or
* more of these queries.
*
* @param allQueries
* the queries to be added
* @tparam S1
* the type of the sub-queries, for which an implicit [[zio.schema.Schema]] is required
* @return
* an instance of the [[zio.elasticsearch.query.DisjunctionMaxQuery]] with queries added.
*/
def queries[S1 <: S: Schema](allQueries: ElasticQuery[S1]*): DisjunctionMaxQuery[S1]

/**
* Adds specified queries to the [[zio.elasticsearch.query.DisjunctionMaxQuery]]. Returned documents must match one or
* more of these queries.
*
* @param allQueries
* the queries to be added
* @return
* an instance of the [[zio.elasticsearch.query.DisjunctionMaxQuery]] with queries added.
*/
def queries(allQueries: ElasticQuery[Any]*): DisjunctionMaxQuery[S]

/**
* Sets the `tieBreaker` parameter for the [[zio.elasticsearch.query.DisjunctionMaxQuery]]. The `tieBreaker` value is
* a floating-point factor between 0 and 1.0 that is used to give more weight to documents that match multiple query
Expand All @@ -234,7 +210,7 @@ sealed trait DisjunctionMaxQuery[S] extends ElasticQuery[S] {
* @param value
* a number to set `tieBreaker` parameter to
* @return
* a new instance of the [[zio.elasticsearch.query.DisjunctionMaxQuery]] with the `tieBreaker` value set.
* an instance of the [[zio.elasticsearch.query.DisjunctionMaxQuery]] enriched with the `tieBreaker` parameter.
*/
def tieBreaker(value: Float): DisjunctionMaxQuery[S]
}
Expand All @@ -247,12 +223,6 @@ private[elasticsearch] final case class DisjunctionMax[S](
def tieBreaker(value: Float): DisjunctionMaxQuery[S] =
self.copy(tieBreaker = Some(value))

def queries[S1 <: S: Schema](allQueries: ElasticQuery[S1]*): DisjunctionMaxQuery[S1] =
self.copy(queries = queries ++ allQueries)

def queries(allQueries: ElasticQuery[Any]*): DisjunctionMaxQuery[S] =
self.copy(queries = queries ++ allQueries)

private[elasticsearch] def toJson(fieldPath: Option[String]): Json = {
val disMaxFields =
Chunk(
Expand Down

0 comments on commit f04af37

Please sign in to comment.