-
Notifications
You must be signed in to change notification settings - Fork 18
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
(dsl): Support regexp
query
#302
Conversation
res <- Executor | ||
.execute(ElasticRequest.search(firstSearchIndex, query)) | ||
.documentAs[TestDocument] | ||
} yield assert(res)(!Assertion.contains(firstDocument)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not make sense to me. Should it maybe be assert(res)(Assertion.contains(firstDocument))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed to just change the name of the test.
test("search for a document using regexp query with case insensitive") { | ||
checkOnce(genDocumentId, genTestDocument, genDocumentId, genTestDocument) { | ||
(firstDocumentId, firstDocument, secondDocumentId, secondDocument) => | ||
for { | ||
_ <- Executor.execute(ElasticRequest.deleteByQuery(firstSearchIndex, matchAll)) | ||
_ <- Executor.execute( | ||
ElasticRequest.upsert[TestDocument](firstSearchIndex, firstDocumentId, firstDocument) | ||
) | ||
_ <- Executor.execute( | ||
ElasticRequest | ||
.upsert[TestDocument](firstSearchIndex, secondDocumentId, secondDocument) | ||
.refreshTrue | ||
) | ||
query = ElasticQuery | ||
.regexp( | ||
field = TestDocument.stringField, | ||
value = s"${firstDocument.stringField.take(1)}.*${firstDocument.stringField.takeRight(1)}" | ||
) | ||
.caseInsensitiveTrue | ||
res <- Executor | ||
.execute(ElasticRequest.search(firstSearchIndex, query)) | ||
.documentAs[TestDocument] | ||
} yield (assert(res)(Assertion.contains(firstDocument)) && assert(res)(!Assertion.contains(secondDocument))) | ||
} | ||
} @@ around( | ||
Executor.execute(ElasticRequest.createIndex(firstSearchIndex)), | ||
Executor.execute(ElasticRequest.deleteIndex(firstSearchIndex)).orDie | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed to just change the name of the previous test.
* [[zio.elasticsearch.query.RegexpQuery]] returns documents that contain terms matching a regular expression. | ||
* | ||
* @param field | ||
* the field for which query is specified for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* the field for which query is specified for | |
* the type-safe field for which query is specified for |
test("regexp") { | ||
val query = regexp("stringField", "t.*st") | ||
val queryTs = regexp(TestDocument.stringField, "t.*st") | ||
val queryWithCaseInsensitive = regexp("stringField", "t.*st").caseInsensitiveTrue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this one. (line 1171)
val query = regexp("stringField", "t.*st") | ||
val queryTs = regexp(TestDocument.stringField, "t.*st") | ||
val queryWithCaseInsensitive = regexp("stringField", "t.*st").caseInsensitiveTrue | ||
val queryTsWithCaseInsensitive = regexp(TestDocument.stringField, "t.*st").caseInsensitiveTrue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this one to queryWithCaseInsensitive
. (line 1171)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And add another one val queryWithSuffix
, where you can do something like this: TestDocument.stringField.raw
.
@@ -2772,6 +2783,40 @@ object ElasticQuerySpec extends ZIOSpecDefault { | |||
assert(queryMixedBoundsWithBoost.toJson(fieldPath = None))(equalTo(expectedMixedBoundsWithBoost.toJson)) && | |||
assert(queryWithFormat.toJson(fieldPath = None))(equalTo(expectedWithFormat.toJson)) | |||
}, | |||
test("regexp") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the same as above here.
) && | ||
assert(queryWithSuffix)( | ||
equalTo(Regexp[TestDocument](field = "stringField.raw", value = "t.*st", caseInsensitive = None)) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sbt prepare divide these asserts in the new lines
Part of #91