Skip to content

Commit cf31617

Browse files
committed
Resolve some comments.
1 parent 45bc91e commit cf31617

File tree

5 files changed

+150
-140
lines changed

5 files changed

+150
-140
lines changed

modules/integration/src/test/scala/zio/elasticsearch/HttpExecutorSpec.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ object HttpExecutorSpec extends IntegrationSpec {
174174
)
175175
.refreshTrue
176176
)
177-
query =
178-
term(field = TestDocument.stringField, value = secondDocumentUpdated.stringField.toLowerCase)
177+
query = term(field = TestDocument.stringField, value = secondDocumentUpdated.stringField.toLowerCase)
179178
aggregation =
180179
filterAggregation(name = "aggregation", query = query).withSubAgg(
181180
maxAggregation("subAggregation", TestDocument.intField)
@@ -2757,7 +2756,7 @@ object HttpExecutorSpec extends IntegrationSpec {
27572756
}
27582757
} @@ after(Executor.execute(ElasticRequest.deleteIndex(geoPolygonIndex)).orDie)
27592758
),
2760-
suite("interval-match query")(
2759+
suite("intervals query")(
27612760
test("intervalMatch returns only matching document") {
27622761
checkOnce(genDocumentId, genTestDocument, Gen.alphaNumericString, genDocumentId, genTestDocument) {
27632762
(idMatch, docMatch, targetWord, idNoMatch, docNoMatch) =>

modules/integration/src/test/scala/zio/elasticsearch/IntegrationSpec.scala

Lines changed: 114 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,114 @@
1-
/*
2-
* Copyright 2022 LambdaWorks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
package zio.elasticsearch
18-
19-
import sttp.client4.httpclient.zio.HttpClientZioBackend
20-
import zio._
21-
import zio.elasticsearch.ElasticQuery.matchAll
22-
import zio.elasticsearch.data.GeoPoint
23-
import zio.elasticsearch.domain._
24-
import zio.elasticsearch.executor.Executor
25-
import zio.elasticsearch.utils.unsafeWrap
26-
import zio.test.Assertion.{containsString, hasMessage}
27-
import zio.test.CheckVariants.CheckN
28-
import zio.test.TestAspect.beforeAll
29-
import zio.test.{Assertion, Gen, TestAspect, ZIOSpecDefault, checkN}
30-
31-
import java.time.LocalDate
32-
33-
trait IntegrationSpec extends ZIOSpecDefault {
34-
35-
val elasticsearchLayer: TaskLayer[Executor] = HttpClientZioBackend.layer() >>> ElasticExecutor.local
36-
37-
val index: IndexName = IndexName("users")
38-
39-
val deleteByQueryIndex: IndexName = IndexName("delete-by-query-index")
40-
41-
val firstSearchIndex: IndexName = IndexName("search-index-1")
42-
43-
val secondSearchIndex: IndexName = IndexName("search-index-2")
44-
45-
val createIndexTestName: IndexName = IndexName("create-index-test-name")
46-
47-
val firstCountIndex: IndexName = IndexName("count-index-1")
48-
49-
val secondCountIndex: IndexName = IndexName("count-index-2")
50-
51-
val updateByQueryIndex: IndexName = IndexName("update-by-query-index")
52-
53-
val geoDistanceIndex: IndexName = IndexName("geo-distance-index")
54-
55-
val refreshFailIndex: IndexName = IndexName("refresh-fail")
56-
57-
val IndexPatternAll: IndexPattern = IndexPattern("_all")
58-
59-
val geoPolygonIndex: IndexName = IndexName("geo-polygon-index")
60-
61-
val prepareElasticsearchIndexForTests: TestAspect[Nothing, Any, Throwable, Any] = beforeAll((for {
62-
_ <- Executor.execute(ElasticRequest.createIndex(index))
63-
_ <- Executor.execute(ElasticRequest.deleteByQuery(index, matchAll).refreshTrue)
64-
} yield ()).provide(elasticsearchLayer))
65-
66-
def genIndexName: Gen[Any, IndexName] =
67-
Gen.stringBounded(10, 40)(Gen.alphaChar).map(name => unsafeWrap(name.toLowerCase)(IndexName))
68-
69-
def genDocumentId: Gen[Any, DocumentId] =
70-
Gen.stringBounded(10, 40)(Gen.alphaNumericChar).map(DocumentId(_))
71-
72-
def genGeoPoint: Gen[Any, GeoPoint] =
73-
for {
74-
latitude <- Gen.bigDecimal(10, 90).map(_.setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble)
75-
longitude <- Gen.bigDecimal(10, 90).map(_.setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble)
76-
} yield GeoPoint(latitude, longitude)
77-
78-
def genTestDocument: Gen[Any, TestDocument] = for {
79-
stringField <- Gen.stringBounded(5, 10)(Gen.alphaChar)
80-
dateField <- Gen.localDate(LocalDate.parse("2010-12-02"), LocalDate.parse("2022-12-05"))
81-
subDocumentList <- Gen.listOfBounded(1, 3)(genTestSubDocument)
82-
intField <- Gen.int(1, 2000)
83-
doubleField <- Gen.double(100, 2000)
84-
booleanField <- Gen.boolean
85-
geoPointField <- genGeoPoint
86-
vectorField <- Gen.listOfN(5)(Gen.int(-10, 10))
87-
} yield TestDocument(
88-
stringField = stringField,
89-
dateField = dateField,
90-
subDocumentList = subDocumentList,
91-
intField = intField,
92-
doubleField = doubleField,
93-
booleanField = booleanField,
94-
geoPointField = geoPointField,
95-
vectorField = vectorField
96-
)
97-
98-
def genTestSubDocument: Gen[Any, TestSubDocument] = for {
99-
stringField1 <- Gen.stringBounded(5, 10)(Gen.alphaChar)
100-
stringField2 <- Gen.stringBounded(5, 10)(Gen.alphaChar)
101-
longField <- Gen.long(1, 75)
102-
intField <- Gen.int(1, 200)
103-
} yield TestSubDocument(
104-
stringField = stringField1,
105-
nestedField = TestNestedField(stringField2, longField),
106-
intField = intField,
107-
intFieldList = Nil
108-
)
109-
110-
def checkOnce: CheckN = checkN(1)
111-
112-
def assertException(substring: String): Assertion[Throwable] = hasMessage(containsString(substring))
113-
}
1+
/*
2+
* Copyright 2022 LambdaWorks
3+
*
4+
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package zio.elasticsearch
19+
20+
import sttp.client4.httpclient.zio.HttpClientZioBackend
21+
import zio._
22+
import zio.elasticsearch.ElasticQuery.matchAll
23+
import zio.elasticsearch.data.GeoPoint
24+
import zio.elasticsearch.domain._
25+
import zio.elasticsearch.executor.Executor
26+
import zio.elasticsearch.utils.unsafeWrap
27+
import zio.test.Assertion.{containsString, hasMessage}
28+
import zio.test.CheckVariants.CheckN
29+
import zio.test.TestAspect.beforeAll
30+
import zio.test.{Assertion, Gen, TestAspect, ZIOSpecDefault, checkN}
31+
32+
import java.time.LocalDate
33+
34+
trait IntegrationSpec extends ZIOSpecDefault {
35+
36+
val elasticsearchLayer: TaskLayer[Executor] = HttpClientZioBackend.layer() >>> ElasticExecutor.local
37+
38+
val index: IndexName = IndexName("users")
39+
40+
val deleteByQueryIndex: IndexName = IndexName("delete-by-query-index")
41+
42+
val firstSearchIndex: IndexName = IndexName("search-index-1")
43+
44+
val secondSearchIndex: IndexName = IndexName("search-index-2")
45+
46+
val createIndexTestName: IndexName = IndexName("create-index-test-name")
47+
48+
val firstCountIndex: IndexName = IndexName("count-index-1")
49+
50+
val secondCountIndex: IndexName = IndexName("count-index-2")
51+
52+
val updateByQueryIndex: IndexName = IndexName("update-by-query-index")
53+
54+
val geoDistanceIndex: IndexName = IndexName("geo-distance-index")
55+
56+
val refreshFailIndex: IndexName = IndexName("refresh-fail")
57+
58+
val IndexPatternAll: IndexPattern = IndexPattern("_all")
59+
60+
val geoPolygonIndex: IndexName = IndexName("geo-polygon-index")
61+
62+
val prepareElasticsearchIndexForTests: TestAspect[Nothing, Any, Throwable, Any] = beforeAll((for {
63+
_ <- Executor.execute(ElasticRequest.createIndex(index))
64+
_ <- Executor.execute(ElasticRequest.deleteByQuery(index, matchAll).refreshTrue)
65+
} yield ()).provide(elasticsearchLayer))
66+
67+
def genIndexName: Gen[Any, IndexName] =
68+
Gen.stringBounded(10, 40)(Gen.alphaChar).map(name => unsafeWrap(name.toLowerCase)(IndexName))
69+
70+
def genDocumentId: Gen[Any, DocumentId] =
71+
Gen.stringBounded(10, 40)(Gen.alphaNumericChar).map(DocumentId(_))
72+
73+
def genGeoPoint: Gen[Any, GeoPoint] =
74+
for {
75+
latitude <- Gen.bigDecimal(10, 90).map(_.setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble)
76+
longitude <- Gen.bigDecimal(10, 90).map(_.setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble)
77+
} yield GeoPoint(latitude, longitude)
78+
79+
def genTestDocument: Gen[Any, TestDocument] = for {
80+
stringField <- Gen.stringBounded(5, 10)(Gen.alphaChar)
81+
dateField <- Gen.localDate(LocalDate.parse("2010-12-02"), LocalDate.parse("2022-12-05"))
82+
subDocumentList <- Gen.listOfBounded(1, 3)(genTestSubDocument)
83+
intField <- Gen.int(1, 2000)
84+
doubleField <- Gen.double(100, 2000)
85+
booleanField <- Gen.boolean
86+
geoPointField <- genGeoPoint
87+
vectorField <- Gen.listOfN(5)(Gen.int(-10, 10))
88+
} yield TestDocument(
89+
stringField = stringField,
90+
dateField = dateField,
91+
subDocumentList = subDocumentList,
92+
intField = intField,
93+
doubleField = doubleField,
94+
booleanField = booleanField,
95+
geoPointField = geoPointField,
96+
vectorField = vectorField
97+
)
98+
99+
def genTestSubDocument: Gen[Any, TestSubDocument] = for {
100+
stringField1 <- Gen.stringBounded(5, 10)(Gen.alphaChar)
101+
stringField2 <- Gen.stringBounded(5, 10)(Gen.alphaChar)
102+
longField <- Gen.long(1, 75)
103+
intField <- Gen.int(1, 200)
104+
} yield TestSubDocument(
105+
stringField = stringField1,
106+
nestedField = TestNestedField(stringField2, longField),
107+
intField = intField,
108+
intFieldList = Nil
109+
)
110+
111+
def checkOnce: CheckN = checkN(1)
112+
113+
def assertException(substring: String): Assertion[Throwable] = hasMessage(containsString(substring))
114+
}

modules/library/src/main/scala/zio/elasticsearch/ElasticQuery.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/*
22
* Copyright 2022 LambdaWorks
33
*
4+
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
67
* You may obtain a copy of the License at
78
*
9+
810
* http://www.apache.org/licenses/LICENSE-2.0
911
*
12+
1013
* Unless required by applicable law or agreed to in writing, software
1114
* distributed under the License is distributed on an "AS IS" BASIS,
1215
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,7 +45,6 @@ object ElasticQuery {
4245
* @return
4346
* an instance of [[zio.elasticsearch.query.BoostingQuery]] that represents the boost query to be performed.
4447
*/
45-
4648
final def boosting[S: Schema](
4749
negativeBoost: Float,
4850
negativeQuery: ElasticQuery[S],

modules/library/src/main/scala/zio/elasticsearch/query/ElasticIntervalRule.scala

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/*
22
* Copyright 2022 LambdaWorks
33
*
4+
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
67
* You may obtain a copy of the License at
78
*
9+
810
* http://www.apache.org/licenses/LICENSE-2.0
911
*
12+
1013
* Unless required by applicable law or agreed to in writing, software
1114
* distributed under the License is distributed on an "AS IS" BASIS,
1215
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,12 +26,12 @@ import zio.json.ast.Json
2326
import zio.json.ast.Json.{Arr, Obj, Str}
2427
import zio.{Chunk, NonEmptyChunk}
2528

26-
sealed trait BoundType
27-
sealed trait Inclusive extends BoundType
28-
sealed trait Exclusive extends BoundType
29+
private[elasticsearch] sealed trait BoundType
30+
private[elasticsearch] sealed trait Inclusive extends BoundType
31+
private[elasticsearch] sealed trait Exclusive extends BoundType
2932

30-
case object InclusiveBound extends Inclusive
31-
case object ExclusiveBound extends Exclusive
33+
private[elasticsearch] case object InclusiveBound extends Inclusive
34+
private[elasticsearch] case object ExclusiveBound extends Exclusive
3235

3336
private[elasticsearch] final case class Bound[B <: BoundType](value: String, boundType: B)
3437

@@ -363,21 +366,10 @@ object ElasticIntervalQuery {
363366
script = script
364367
)
365368

366-
if (
367-
List(
368-
after,
369-
before,
370-
containedBy,
371-
containing,
372-
notContainedBy,
373-
notContaining,
374-
notOverlapping,
375-
overlapping,
376-
script
377-
).forall(_.isEmpty)
378-
) None
379-
else Some(filter)
380-
369+
Some(filter).filterNot(_ =>
370+
List(after, before, containedBy, containing, notContainedBy, notContaining, notOverlapping, overlapping, script)
371+
.forall(_.isEmpty)
372+
)
381373
}
382374

383375
def intervalFuzzy[S](term: String): IntervalFuzzy[S] =

modules/library/src/test/scala/zio/elasticsearch/ElasticQuerySpec.scala

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2022 LambdaWorks
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package zio.elasticsearch
218

319
import zio.Chunk
@@ -2611,12 +2627,12 @@ object ElasticQuerySpec extends ZIOSpecDefault {
26112627
| "boosting": {
26122628
| "positive": {
26132629
| "terms": {
2614-
| "booleanField": [true, false]
2615-
| }
2630+
| "booleanField": [ true, false ]
2631+
| }
26162632
| },
26172633
| "negative": {
26182634
| "exists": {
2619-
| "field": "stringField"
2635+
| "field": "stringField"
26202636
| }
26212637
| },
26222638
| "negative_boost": 0.5

0 commit comments

Comments
 (0)