-
Notifications
You must be signed in to change notification settings - Fork 20
(dsl): Support intervalQuery #647
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
Open
markok4
wants to merge
41
commits into
lambdaworks:main
Choose a base branch
from
markok4:IntervalsQuery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
861a986
Done: matches case for IntervalQuery
markok4 7bb2df6
Disable empty chunk in interval allof, Wildcard (with cointains, star…
markok4 907980b
Implement IntervalRange test
markok4 3b97832
Implement: export methods from Queries.scala to ElasticIntervalQuery.…
markok4 ee269c2
Implement: documentation in ElasticQuery.scala
markok4 441fe9f
Implement: move methods to another file, fix tests
markok4 af9b2fe
Fix formater bug, create ElasticIntervalQuerySpec
markok4 805f6bd
Fix IntervalRange, Change order of methods in ElasticQuery
markok4 f9a4a13
Add ElasticIntervalQuery.scala
markok4 84c908b
Add HasAnalyzer and HasUseField, correct some mistakes
markok4 d5b8bc8
Error: Scalafmt
markok4 7af2c13
Work on It tests
markok4 ba54dc1
Add integration tests for IntervalMatch
markok4 593f575
Refactor code in HttpExecutorSpec and create suite for IntervalMatch
markok4 5f42ed1
Add elastic_interval_query.md file
markok4 ff1916d
Complete changes on Boosting, refactor on type-safe useField
markok4 ca243e9
Use fieldPath
markok4 640500d
Implemented methods for gt,gte,lt,lte
markok4 6308187
Fix PR comments
markok4 41df198
Revert boost, add another type parameter into HasUseField
markok4 f7cb287
Fix some warnings about casting.
markok4 a136f4f
Try to remove strange chars.
markok4 7391cec
Done sbt prepared
markok4 45bc91e
Remove manually strange chars
markok4 cf31617
Resolve some comments.
markok4 3f44d44
Change elastic_interval_query.md file.
markok4 dfece62
Fix line endings and cleanup .gitattributes
markok4 500610f
Remove strange chars.
markok4 72715df
Remove space from ElasticQuerySpec.
markok4 7941fe3
Return copyright to HttpExecutorSpec.
markok4 26150f1
Add copyright in intervalSpec and some changes.
markok4 4d60d5f
Try to fix.
markok4 c7eab4e
Fix space in copyright
markok4 377bf8c
Fix space in copyright
markok4 b21a202
Fix space in copyright
markok4 b14e4d9
Add to sidebars.js
markok4 72e782b
Move ElasticInterval object in separated file, fix some problems.
markok4 626dfda
Add line in elastic_query_interval.md and do sbt prepare
markok4 61a4949
Done.
markok4 1aae089
Some fixes.
markok4 689ab2e
Add unit tests for query.
markok4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| * text=auto eol=lf | ||
| sbt linguist-vendored |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| id: elastic_interval_query | ||
| title: "Overview" | ||
| --- | ||
|
|
||
| The `Intervals` query allows for advanced search queries based on intervals between words in specific fields. | ||
| This query provides flexibility for conditions. | ||
|
|
||
| To use the `Intervals` query, import the following: | ||
| ```scala | ||
| import zio.elasticsearch.query.IntervalQuery | ||
| import zio.elasticsearch.ElasticQuery._ | ||
| ``` | ||
|
|
||
| You can create a basic `Intervals` query` using the `intervals` method: | ||
| ```scala | ||
| val query: IntervalQuery[Any] = intervals(field = "content", rule = intervalMatch("targetWord")) | ||
| ``` | ||
|
|
||
| To define `field` in a type-safe manner, use the overloaded `useField` method with field definitions from your document: | ||
| ```scala | ||
| val queryWithSafeField: IntervalQuery[Document] = | ||
| intervals(field = Document.stringField, rule = intervalMatch("targetWord")) | ||
| ``` | ||
|
|
||
| If you want to specify which fields should be searched, you can use the `useField` method: | ||
| ```scala | ||
| val queryWithField: IntervalQuery[Document] = | ||
| intervals(field = "content", rule = intervalMatch("targetWord").useField(Document.stringField)) | ||
| ``` | ||
|
|
||
| If you want to define the `maxGaps` parameter, use the `maxGaps` method: | ||
| ```scala | ||
| val queryWithMaxGaps: IntervalQuery[Document] = | ||
| intervals(field = "content", rule = intervalMatch("targetWord").maxGaps(2)) | ||
| ``` | ||
|
|
||
| If you want to specify the word order requirement, use the `orderedOn` method: | ||
| ```scala | ||
| val queryWithOrder: IntervalQuery[Document] = | ||
| intervals(field = "content", rule = intervalMatch("targetWord").orderedOn) | ||
| ``` | ||
|
|
||
| You can also apply additional filters to the query: | ||
| ```scala | ||
| val queryWithFilter: IntervalQuery[Document] = | ||
| intervals(field = "content", rule = intervalMatch("targetWord").filter(IntervalFilter.someFilter)) | ||
| ``` | ||
|
|
||
| Alternatively, you can construct the query manually with all parameters: | ||
| ```scala | ||
| val queryManually: IntervalQuery[Document] = | ||
| IntervalQuery( | ||
| field = "content", | ||
| rule = intervalMatch("targetWord") | ||
| .maxGaps(2) | ||
| .orderedOn | ||
| .filter(IntervalFilter.someFilter) | ||
| .analyzer("standard") | ||
| ) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
modules/library/src/main/scala/zio/elasticsearch/ElasticIntervalRule.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import zio.NonEmptyChunk | ||
| import zio.elasticsearch.query.{ | ||
| IntervalAllOf, | ||
| IntervalAnyOf, | ||
| IntervalFilter, | ||
| IntervalFuzzy, | ||
| IntervalMatch, | ||
| IntervalPrefix, | ||
| IntervalRange, | ||
| IntervalRegexp, | ||
| IntervalRule, | ||
| IntervalWildcard, | ||
| Regexp | ||
| } | ||
| import zio.json.ast.Json | ||
|
|
||
| object ElasticIntervalRule { | ||
|
|
||
| def intervalAllOf[S](intervals: NonEmptyChunk[IntervalRule]): IntervalAllOf[S] = | ||
| IntervalAllOf(intervals = intervals, maxGaps = None, ordered = None, filter = None) | ||
|
|
||
| def intervalAnyOf[S](intervals: NonEmptyChunk[IntervalRule]): IntervalAnyOf[S] = | ||
| IntervalAnyOf(intervals = intervals, filter = None) | ||
|
|
||
| def intervalContains[S](pattern: String): IntervalWildcard[S] = | ||
| IntervalWildcard(s"*$pattern*", analyzer = None, useField = None) | ||
|
|
||
| def intervalEndsWith[S](pattern: String): IntervalWildcard[S] = | ||
| IntervalWildcard(s"*$pattern", analyzer = None, useField = None) | ||
|
|
||
| def intervalFilter[S]( | ||
| after: Option[IntervalRule] = None, | ||
| before: Option[IntervalRule] = None, | ||
| containedBy: Option[IntervalRule] = None, | ||
| containing: Option[IntervalRule] = None, | ||
| notContainedBy: Option[IntervalRule] = None, | ||
| notContaining: Option[IntervalRule] = None, | ||
| notOverlapping: Option[IntervalRule] = None, | ||
| overlapping: Option[IntervalRule] = None, | ||
| script: Option[Json] = None | ||
| ): Option[IntervalFilter[S]] = { | ||
|
|
||
| val filter: IntervalFilter[S] = IntervalFilter( | ||
| after = after, | ||
| before = before, | ||
| containedBy = containedBy, | ||
| containing = containing, | ||
| notContainedBy = notContainedBy, | ||
| notContaining = notContaining, | ||
| notOverlapping = notOverlapping, | ||
| overlapping = overlapping, | ||
| script = script | ||
| ) | ||
|
|
||
| Some(filter).filterNot(_ => | ||
| List(after, before, containedBy, containing, notContainedBy, notContaining, notOverlapping, overlapping, script) | ||
| .forall(_.isEmpty) | ||
| ) | ||
| } | ||
|
|
||
| def intervalFuzzy[S](term: String): IntervalFuzzy[S] = | ||
| IntervalFuzzy( | ||
| term = term, | ||
| prefixLength = None, | ||
| transpositions = None, | ||
| fuzziness = None, | ||
| analyzer = None, | ||
| useField = None | ||
| ) | ||
|
|
||
| def intervalMatch[S](query: String): IntervalMatch[S] = | ||
| IntervalMatch(query = query, analyzer = None, useField = None, maxGaps = None, ordered = None, filter = None) | ||
|
|
||
| def intervalPrefix[S](prefix: String): IntervalPrefix[S] = | ||
| IntervalPrefix(prefix = prefix, analyzer = None, useField = None) | ||
|
|
||
| def intervalRange[S]( | ||
| lower: Option[IntervalRule] = None, | ||
| upper: Option[IntervalRule] = None, | ||
| analyzer: Option[String] = None, | ||
| useField: Option[String] = None | ||
| ): IntervalRange[S] = | ||
| IntervalRange(lower = lower, upper = upper, analyzer = analyzer, useField = useField) | ||
|
|
||
| def intervalRegexp[S](pattern: Regexp[S]): IntervalRegexp[S] = | ||
| IntervalRegexp(pattern = pattern, analyzer = None, useField = None) | ||
|
|
||
| def intervalStartsWith[S](pattern: String): IntervalWildcard[S] = | ||
| IntervalWildcard(s"$pattern*", analyzer = None, useField = None) | ||
|
|
||
| def intervalWildcard[S](pattern: String): IntervalWildcard[S] = | ||
| IntervalWildcard(pattern = pattern, analyzer = None, useField = None) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.