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

Restructure library #187

Merged
merged 6 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package example

import zio._
import zio.elasticsearch.ElasticQuery.matchAll
import zio.elasticsearch._
import zio.elasticsearch.query.ElasticQuery
import zio.elasticsearch.request.{CreationOutcome, DeletionOutcome}
import zio.elasticsearch.{DocumentId, ElasticRequest, Elasticsearch, Routing, ZIODocumentOps}

final case class RepositoriesElasticsearch(elasticsearch: Elasticsearch) {

Expand Down
2 changes: 1 addition & 1 deletion modules/example/src/main/scala/example/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import zio.elasticsearch.IndexName
import zio.elasticsearch._

package object example {
final val Index: IndexName = IndexName("repositories")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import zio.elasticsearch.highlights.Highlights
import zio.elasticsearch.query.ElasticQuery
import zio.elasticsearch.query.sort.Sort
import zio.elasticsearch.request._
import zio.elasticsearch.request.options._
import zio.elasticsearch.result.{
AggregationResult,
GetResult,
Expand Down Expand Up @@ -370,7 +371,7 @@ object ElasticRequest {
self.copy(routing = Some(value))

lazy val body: String = requests.flatMap { r =>
r match {
(r: @unchecked) match {
case Create(index, document, _, routing) =>
List(getActionAndMeta("create", List(("_index", Some(index)), ("routing", routing))), document.json)
case CreateWithId(index, id, document, _, routing) =>
Expand Down Expand Up @@ -551,7 +552,7 @@ object ElasticRequest {
extends ElasticRequest[SearchResult]
with HasFrom[SearchRequest]
with HasRouting[SearchRequest]
with WithSort[SearchRequest]
with HasSort[SearchRequest]
with HasSize[SearchRequest] {
def aggregate(aggregation: ElasticAggregation): SearchAndAggregateRequest

Expand Down Expand Up @@ -623,7 +624,7 @@ object ElasticRequest {
with HasFrom[SearchAndAggregateRequest]
with HasRouting[SearchAndAggregateRequest]
with HasSize[SearchAndAggregateRequest]
with WithSort[SearchAndAggregateRequest] {
with HasSort[SearchAndAggregateRequest] {
def highlights(value: Highlights): SearchAndAggregateRequest

def searchAfter(value: Json): SearchAndAggregateRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package zio.elasticsearch.aggregation

import zio.elasticsearch.ElasticAggregation.multipleAggregations
import zio.elasticsearch.ElasticPrimitive.ElasticPrimitiveOps
import zio.elasticsearch.aggregation.options._
import zio.json.ast.Json
import zio.json.ast.Json.Obj

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 LambdaWorks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.elasticsearch.aggregation.options

import zio.elasticsearch.aggregation.{MultipleAggregations, SingleElasticAggregation}

private[elasticsearch] trait WithAgg {

/**
* Adds a new aggregation to the list of aggregations represented as [[MultipleAggregations]].
*
* @param agg
* the [[SingleElasticAggregation]] to add
* @return
* a new instance of [[MultipleAggregations]] with the specified aggregation added to its list of aggregations.
*/
def withAgg(agg: SingleElasticAggregation): MultipleAggregations
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
* limitations under the License.
*/

package zio.elasticsearch
package zio.elasticsearch.aggregation.options

package object result {
class ElasticException(message: String) extends RuntimeException(message)
import zio.elasticsearch.aggregation.SingleElasticAggregation

final case class DecodingException(message: String) extends ElasticException(message)
private[elasticsearch] trait WithSubAgg[A <: WithSubAgg[A]] {

case object UnauthorizedException extends ElasticException("Wrong credentials provided.")

final case class VersionConflictException(succeeded: Int, failed: Int)
extends ElasticException(
s"There are $failed documents failed due to version conflict, but $succeeded documents are updated successfully."
)
/**
* Adds a sub-aggregation to the aggregation.
*
* @param subAgg
* the [[SingleElasticAggregation]] to add as sub-aggregation
* @return
* a new instance of the [[zio.elasticsearch.aggregation.ElasticAggregation]] with the given sub-aggregation.
*/
def withSubAgg(subAgg: SingleElasticAggregation): A
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private[elasticsearch] object TermsAggregationBucket {
val docCount = allFields("doc_count").asInstanceOf[Int]
val subAggs = allFields.collect {
case (field, data) if field != "key" && field != "doc_count" =>
field match {
(field: @unchecked) match {
case str if str.contains("terms#") =>
(field.split("#")(1), data.asInstanceOf[TermsAggregationResponse])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package zio.elasticsearch.query

import zio.elasticsearch.ElasticPrimitive._
import zio.elasticsearch.query.options._
import zio.json.ast.Json
import zio.json.ast.Json.{Arr, Num, Obj, Str}
import zio.schema.Schema
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2022 LambdaWorks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.elasticsearch.query.options

private[elasticsearch] trait HasBoost[Q <: HasBoost[Q]] {

/**
* Sets the `boost` parameter for this [[zio.elasticsearch.query.ElasticQuery]]. The `boost` value is a positive
* multiplier applied to the score of documents matching the query. A value greater than 1 increases the relevance
* score of matching documents, while a value less than 1 decreases it. The default `boost` value is 1.
*
* @param value
* a non-negative real number to set `boost` parameter to
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `boost` value set.
*/
def boost(value: Double): Q
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022 LambdaWorks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.elasticsearch.query.options

private[elasticsearch] trait HasCaseInsensitive[Q <: HasCaseInsensitive[Q]] {

/**
* Sets the `caseInsensitive` parameter for the [[zio.elasticsearch.query.ElasticQuery]]. Case-insensitive queries
* match text regardless of the case of the characters in the query string. By default, queries are case-sensitive.
*
* @param value
* the [[scala.Boolean]] value for `caseInsensitive` parameter
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `caseInsensitive` value set.
*/
def caseInsensitive(value: Boolean): Q

/**
* Sets the `caseInsensitive` parameter to `false` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as
* [[caseInsensitive]](false).
*
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `caseInsensitive` value set to `false`.
* @see
* #caseInsensitive
*/
final def caseInsensitiveFalse: Q = caseInsensitive(false)

/**
* Sets the `caseInsensitive` parameter to `true` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as
* [[caseInsensitive]](true).
*
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `caseInsensitive` value set to `true`.
* @see
* #caseInsensitive
*/
final def caseInsensitiveTrue: Q = caseInsensitive(true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2022 LambdaWorks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.elasticsearch.query.options

private[elasticsearch] trait HasIgnoreUnmapped[Q <: HasIgnoreUnmapped[Q]] {

/**
* Sets the `ignoreUnmapped` parameter to control whether to ignore unmapped fields and return empty hits.
*
* @param value
* the `boolean` value for `ignoreUnmapped` parameter
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `ignoreUnmapped` value set.
*/
def ignoreUnmapped(value: Boolean): Q

/**
* Sets the `ignoreUnmapped` parameter to `false` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as
* [[ignoreUnmapped]](false).
*
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `ignoreUnmapped` value set to `false`.
* @see
* #ignoreUnmapped
*/
final def ignoreUnmappedFalse: Q = ignoreUnmapped(false)

/**
* Sets the `ignoreUnmapped` parameter to `true` for this [[zio.elasticsearch.query.ElasticQuery]]. Same as
* [[ignoreUnmapped]](true).
*
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the `ignoreUnmapped` value set to `true`.
* @see
* #ignoreUnmapped
*/
final def ignoreUnmappedTrue: Q = ignoreUnmapped(true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2022 LambdaWorks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.elasticsearch.query.options

import zio.elasticsearch.query.InnerHits

private[elasticsearch] trait HasInnerHits[Q <: HasInnerHits[Q]] {

/**
* Sets the inner hits for this [[zio.elasticsearch.query.ElasticQuery]] to the default `InnerHits()` value.
*
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the default inner hits.
*/
final def innerHits: Q = innerHits(InnerHits())

/**
* Sets the inner hits configuration for the [[zio.elasticsearch.query.NestedQuery]].
*
* @param innerHits
* the configuration for inner hits
* @return
* a new instance of the [[zio.elasticsearch.query.ElasticQuery]] with the specified inner hits configuration.
*/
def innerHits(innerHits: InnerHits): Q
}
Loading