Skip to content

Commit

Permalink
change from = to :
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentescoffier committed Jan 10, 2024
1 parent d713cda commit a5fd959
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ Request : `/cars?search=color!Red`

3. Using the greater than operator `>`
Request : `/cars?search=creationyear>2017`
> Note: You can use the `>=` operator as well.
> Note: You can use the `>:` operator as well.
![greater than operator example](./docs/images/greater-than-example.gif)

4. Using the less than operator `<`
Request : `/cars?search=price<100000`
> Note: You can use the `<=` operator as well.
> Note: You can use the `<:` operator as well.
![less than operator example](./docs/images/less-than-example.gif)

Expand Down
4 changes: 2 additions & 2 deletions src/main/antlr4/Query.g4
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ GT
;
GTE
: '>='
: '>:'
;
LT
: '<'
;
LTE
: '<='
: '<:'
;
EQ
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/sipios/springsearch/SearchOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ enum class SearchOperation {
EQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN, STARTS_WITH, ENDS_WITH, CONTAINS, DOESNT_START_WITH, DOESNT_END_WITH, DOESNT_CONTAIN, GREATER_THAN_EQUALS, LESS_THAN_EQUALS;

companion object {
val SIMPLE_OPERATION_SET = arrayOf(":", "!", ">", "<", "~", ">=", "<=")
val SIMPLE_OPERATION_SET = arrayOf(":", "!", ">", "<", "~", ">:", "<:")
val ZERO_OR_MORE_REGEX = "*"
val OR_OPERATOR = "OR"
val AND_OPERATOR = "AND"
Expand All @@ -23,8 +23,8 @@ enum class SearchOperation {
"!" -> NOT_EQUALS
">" -> GREATER_THAN
"<" -> LESS_THAN
">=" -> GREATER_THAN_EQUALS
"<=" -> LESS_THAN_EQUALS
">:" -> GREATER_THAN_EQUALS
"<:" -> LESS_THAN_EQUALS
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,13 @@ class SpringSearchApplicationTest {

var specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", true)
).withSearch("createdAt>='2019-01-01'").build()
).withSearch("createdAt>:'2019-01-01'").build()
var specificationUsers = userRepository.findAll(specification)
Assertions.assertEquals(2, specificationUsers.size)

specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", true)
).withSearch("createdAt>='2019-01-04'").build()
).withSearch("createdAt>:'2019-01-04'").build()
specificationUsers = userRepository.findAll(specification)
Assertions.assertEquals(0, specificationUsers.size)
}
Expand All @@ -619,13 +619,13 @@ class SpringSearchApplicationTest {

var specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", true)
).withSearch("createdAt<='2019-01-01'").build()
).withSearch("createdAt<:'2019-01-01'").build()
var specificationUsers = userRepository.findAll(specification)
Assertions.assertEquals(1, specificationUsers.size)

specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", true)
).withSearch("createdAt<='2019-01-03'").build()
).withSearch("createdAt<:'2019-01-03'").build()
specificationUsers = userRepository.findAll(specification)
Assertions.assertEquals(2, specificationUsers.size)
}
Expand Down Expand Up @@ -809,7 +809,7 @@ class SpringSearchApplicationTest {

val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedInstantAt>='2020-01-11T09:20:30Z'").build()
).withSearch("updatedInstantAt>:'2020-01-11T09:20:30Z'").build()
val robotUsers = userRepository.findAll(specification)
Assertions.assertEquals(1, robotUsers.size)
Assertions.assertEquals("robot", robotUsers[0].userFirstName)
Expand All @@ -827,7 +827,7 @@ class SpringSearchApplicationTest {

val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedInstantAt<='2020-01-11T09:20:30Z'").build()
).withSearch("updatedInstantAt<:'2020-01-11T09:20:30Z'").build()
val robotUsers = userRepository.findAll(specification)
Assertions.assertEquals(1, robotUsers.size)
Assertions.assertEquals("john", robotUsers[0].userFirstName)
Expand Down Expand Up @@ -879,7 +879,7 @@ class SpringSearchApplicationTest {
userRepository.save(Users(userFirstName = "robot2", updatedAt = LocalDateTime.parse("2020-01-12T10:20:30")))
val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedAt>='2020-01-11T10:20:30'").build()
).withSearch("updatedAt>:'2020-01-11T10:20:30'").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(2, users.size)
Assertions.assertFalse(users.any { user -> user.userFirstName == "john" })
Expand All @@ -892,7 +892,7 @@ class SpringSearchApplicationTest {
userRepository.save(Users(userFirstName = "robot2", updatedAt = LocalDateTime.parse("2020-01-12T10:20:30")))
val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedAt<='2020-01-11T10:20:30'").build()
).withSearch("updatedAt<:'2020-01-11T10:20:30'").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(2, users.size)
Assertions.assertFalse(users.any { user -> user.userFirstName == "robot2" })
Expand Down Expand Up @@ -958,7 +958,7 @@ class SpringSearchApplicationTest {

val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedDateAt<='2020-01-11'").build()
).withSearch("updatedDateAt<:'2020-01-11'").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(2, users.size)
Assertions.assertFalse(users.any { user -> user.userFirstName == "robot2" })
Expand All @@ -972,7 +972,7 @@ class SpringSearchApplicationTest {

val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedDateAt>='2020-01-11'").build()
).withSearch("updatedDateAt>:'2020-01-11'").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(2, users.size)
Assertions.assertFalse(users.any { user -> user.userFirstName == "john" })
Expand Down Expand Up @@ -1025,7 +1025,7 @@ class SpringSearchApplicationTest {

val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedTimeAt<='10:20:30'").build()
).withSearch("updatedTimeAt<:'10:20:30'").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(2, users.size)
Assertions.assertFalse(users.any { user -> user.userFirstName == "robot2" })
Expand All @@ -1039,7 +1039,7 @@ class SpringSearchApplicationTest {

val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("updatedTimeAt>='10:20:30'").build()
).withSearch("updatedTimeAt>:'10:20:30'").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(2, users.size)
Assertions.assertFalse(users.any { user -> user.userFirstName == "john" })
Expand Down Expand Up @@ -1143,7 +1143,7 @@ class SpringSearchApplicationTest {
userRepository.save(Users(userFirstName = "joe", userChildrenNumber = 4))
val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("userChildrenNumber<=2").build()
).withSearch("userChildrenNumber<:2").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(1, users.size)
Assertions.assertEquals("john", users[0].userFirstName)
Expand All @@ -1156,7 +1156,7 @@ class SpringSearchApplicationTest {
userRepository.save(Users(userFirstName = "joe", userChildrenNumber = 4))
val specification = SpecificationsBuilder<Users>(
SearchSpec::class.constructors.first().call("", false)
).withSearch("userChildrenNumber>=3").build()
).withSearch("userChildrenNumber>:3").build()
val users = userRepository.findAll(specification)
Assertions.assertEquals(2, users.size)
}
Expand Down

0 comments on commit a5fd959

Please sign in to comment.