Skip to content

Commit

Permalink
remove "is" query
Browse files Browse the repository at this point in the history
  • Loading branch information
kadhonn committed Oct 21, 2023
1 parent eced339 commit a8c6d55
Show file tree
Hide file tree
Showing 15 changed files with 8 additions and 122 deletions.
2 changes: 0 additions & 2 deletions QUERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ potentially nested) forms. Please note that expressions are case-insensitive:
| Not | The child-expression has to be false so that the whole expression is true | `not <expression>` |
| After | Filter events starting at or after the given date | `after <date>` |
| Before | Filter events starting at or before the given date | `before <date>` |
| Is | Filter events belonging to a certain category | `is <category>` |
| Grouping | Marker to identify how expression should be grouped | `( <expression> )` |
| Duration Longer | Filter events on their duration in hours (inclusive), events without endDate have 0 duration | `durationLonger <number` |
| Duration Shorter | Filter events on their duration in hours (inclusive), events without endDate have 0 duration | `durationShorter <number>` |
Expand All @@ -38,7 +37,6 @@ where
"any field". Please note that * is a special character and thus the quotes are needed. Also note that the fieldname
matching is case-sensitive, so the fieldnames `name` and `NAME` are different fields.
* `<date>` is a `<text>` in the ISO Local Date format `YYYY-MM-DD`, for example `2023-05-27`
* `<category>` is a `<text>` which value has to be one of `MUSIC`,`TECH`,`ART`,`OTHER`

In contrast to other queries or math there is no operator precedence here, they will be ordered/grouped randomly
(depending solely on the parser). So make sure to use the grouping `(...)` mechanism!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import org.springframework.stereotype.Service
class CategoryEnricher : Enricher {

override fun enrich(e: Event): Event {
val type = e.data[SemanticKeys.TYPE]
val data = e.data.toMutableMap()
data[SemanticKeys.CATEGORY] = EventCategory.OTHER.name
val type = data[SemanticKeys.TYPE]
if (!type.isNullOrBlank()) {
val category = EventCategory.getForType(type)
if (category != null) {
val data = e.data.toMutableMap()
data[SemanticKeys.CATEGORY] = category.name
return Event(e.name, e.startDate, data)
}
}
return e
return Event(e.name, e.startDate, data)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package base.boudicca.publisher.event.html.service
import base.boudicca.Event
import base.boudicca.EventCategory
import base.boudicca.SemanticKeys
import base.boudicca.api.search.BoudiccaQueryBuilder
import base.boudicca.api.search.BoudiccaQueryBuilder.after
import base.boudicca.api.search.BoudiccaQueryBuilder.and
import base.boudicca.api.search.BoudiccaQueryBuilder.before
import base.boudicca.api.search.BoudiccaQueryBuilder.contains
import base.boudicca.api.search.BoudiccaQueryBuilder.durationLonger
import base.boudicca.api.search.BoudiccaQueryBuilder.durationShorter
import base.boudicca.api.search.BoudiccaQueryBuilder.equals
import base.boudicca.api.search.BoudiccaQueryBuilder.isQuery
import base.boudicca.api.search.QueryDTO
import base.boudicca.api.search.Search
import base.boudicca.api.search.SearchResultDTO
Expand Down Expand Up @@ -58,8 +56,8 @@ class EventService @Autowired constructor(@Value("\${boudicca.search.url}") priv
if (!searchDTO.name.isNullOrBlank()) {
queryParts.add(contains("*", searchDTO.name!!))
}
if (!searchDTO.category.isNullOrBlank() && searchDTO.category != SEARCH_TYPE_ALL && BoudiccaQueryBuilder.Category.entries.any { searchDTO.category == it.name }) {
queryParts.add(isQuery(BoudiccaQueryBuilder.Category.valueOf(searchDTO.category!!)))
if (!searchDTO.category.isNullOrBlank() && searchDTO.category != SEARCH_TYPE_ALL) {
queryParts.add(equals(SemanticKeys.CATEGORY, searchDTO.category!!))
}
if (!searchDTO.locationCity.isNullOrBlank()) {
queryParts.add(equals(SemanticKeys.LOCATION_CITY, searchDTO.locationCity!!))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import java.time.format.DateTimeFormatter

object BoudiccaQueryBuilder {

enum class Category {
MUSIC,
TECH,
ART,
OTHER
}

fun and(subQueries: Iterable<String>): String {
return booleanMultiQuery(subQueries, "and")
}
Expand All @@ -35,10 +28,6 @@ object BoudiccaQueryBuilder {
return "not ($query)"
}

fun isQuery(category: Category): String {
return "is ${category.name}"
}

fun after(localDate: LocalDate): String {
return "after " + DateTimeFormatter.ISO_LOCAL_DATE.format(localDate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import base.boudicca.api.search.BoudiccaQueryBuilder.durationLonger
import base.boudicca.api.search.BoudiccaQueryBuilder.durationShorter
import base.boudicca.api.search.BoudiccaQueryBuilder.equals
import base.boudicca.api.search.BoudiccaQueryBuilder.escapeText
import base.boudicca.api.search.BoudiccaQueryBuilder.isQuery
import base.boudicca.api.search.BoudiccaQueryBuilder.not
import base.boudicca.api.search.BoudiccaQueryBuilder.or
import org.junit.jupiter.api.Assertions.assertEquals
Expand Down Expand Up @@ -127,13 +126,6 @@ class BoudiccaQueryBuilderTest {
assertEquals("before 2023-10-06", query)
}

@Test
fun simpleIs() {
val query = isQuery(BoudiccaQueryBuilder.Category.ART)

assertEquals("is ART", query)
}

@Test
fun simpleDurationLonger() {
val query = durationLonger(5.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SearchService @Autowired constructor(
queryParts.add("\"*\" contains " + escape(searchDTO.name))
}
if (!searchDTO.category.isNullOrBlank() && searchDTO.category != SEARCH_TYPE_ALL) {
queryParts.add("is " + escape(searchDTO.category))
queryParts.add(SemanticKeys.CATEGORY + " equals " + escape(searchDTO.category))
}
if (!searchDTO.locationCity.isNullOrBlank()) {
queryParts.add(SemanticKeys.LOCATION_CITY + " equals " + escape(searchDTO.locationCity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ class AfterExpression(
text: String,
) : DateExpression("AFTER", text)

class IsExpression(
text: String,
) : TextExpression("IS", text)

class DurationShorterExpression(
duration: Number,
) : NumberExpression("DURATIONSHORTER", duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Lexer(private val query: String) {
"contains" -> tokens.add(Token(TokenType.CONTAINS, null))
"before" -> tokens.add(Token(TokenType.BEFORE, null))
"after" -> tokens.add(Token(TokenType.AFTER, null))
"is" -> tokens.add(Token(TokenType.IS, null))
"durationlonger" -> tokens.add(Token(TokenType.DURATIONLONGER, null))
"durationshorter" -> tokens.add(Token(TokenType.DURATIONSHORTER, null))
else -> tokens.add(Token(TokenType.TEXT, token))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Parser(private val tokens: List<Token>) {
TokenType.TEXT -> parseFieldAndTextExpression()
TokenType.NOT -> parseNotExpression()
TokenType.GROUPING_OPEN -> parseGroupOpen()
TokenType.BEFORE, TokenType.AFTER, TokenType.IS, TokenType.DURATIONLONGER, TokenType.DURATIONSHORTER -> {
TokenType.BEFORE, TokenType.AFTER, TokenType.DURATIONLONGER, TokenType.DURATIONSHORTER -> {
parseSingleFieldExpression(token)
}

Expand All @@ -47,7 +47,6 @@ class Parser(private val tokens: List<Token>) {
lastExpression = when (token.getType()) {
TokenType.BEFORE -> BeforeExpression(textToken.getToken()!!)
TokenType.AFTER -> AfterExpression(textToken.getToken()!!)
TokenType.IS -> IsExpression(textToken.getToken()!!)
TokenType.DURATIONSHORTER -> DurationShorterExpression(parseNumber(textToken.getToken()!!))
TokenType.DURATIONLONGER -> DurationLongerExpression(parseNumber(textToken.getToken()!!))
else -> throw IllegalStateException("unknown token type ${token.getType()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ enum class TokenType {
NOT,
BEFORE,
AFTER,
IS,
GROUPING_OPEN,
GROUPING_CLOSE,
DURATIONLONGER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,6 @@ class SimpleEvaluator(rawEvents: Collection<Event>) : Evaluator {
}
}

is IsExpression -> {
if (!event.containsKey(SemanticKeys.TYPE)) {
return false
}
val category = base.boudicca.EventCategory.getForType(event[SemanticKeys.TYPE])
val expressionCategory = expression.getText().uppercase()
if (category == null) {
return expressionCategory == "OTHER"
}
return expressionCategory == category.name
}

is DurationLongerExpression -> {
val duration = EvaluatorUtil.getDuration(event)
return duration >= expression.getNumber().toDouble()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,6 @@ class LexerTest {
assertEquals("text", tokens[15].getToken())
}

@Test
fun testIsOperator() {
val tokens = callLexer("is")
assertEquals(1, tokens.size)
assertEquals(TokenType.IS, tokens[0].getType())
}

@Test
fun testDurationLongerOperator() {
val tokens = callLexer("durationLonger")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,6 @@ class ParserTest {
)
}

@Test
fun testIs() {
assertEquals(
"IS('MUSIC')",
callParser(
`is`(), text("MUSIC")
)
)
}

@Test
fun testDurationShorter() {
assertEquals(
Expand All @@ -229,10 +219,6 @@ class ParserTest {
)
}

private fun `is`(): Token {
return Token(TokenType.IS, null)
}

private fun before(): Token {
return Token(TokenType.BEFORE, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ class QueryTest {
assertEquals("event2", events.first()["name"])
}

@Test
fun queryWithIs() {
val events =
evaluateQuery("is music and name contains event")
assertEquals(1, events.size)
assertEquals("event1", events.first()["name"])
}

@Test
fun queryWithDurationLonger() {
val events =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,49 +170,6 @@ class SimpleEvaluatorTest {
assertEquals(2, events.size)
}

@Test
fun simpleIsMusic() {
val events =
callEvaluator(
IsExpression("MUSIC"),
listOf(
mapOf(SemanticKeys.TYPE to "konzert"),
mapOf(SemanticKeys.TYPE to "theater"),
)
)
assertEquals(1, events.size)
assertEquals("konzert", events.first().data[SemanticKeys.TYPE])
}

@Test
fun simpleIsMusicIgnoreCase() {
val events =
callEvaluator(
IsExpression("muSIC"),
listOf(
mapOf(SemanticKeys.TYPE to "konzert"),
mapOf(SemanticKeys.TYPE to "theater"),
)
)
assertEquals(1, events.size)
assertEquals("konzert", events.first().data[SemanticKeys.TYPE])
}

@Test
fun simpleIsOther() {
val events =
callEvaluator(
IsExpression("other"),
listOf(
mapOf(SemanticKeys.TYPE to "konzert"),
mapOf(SemanticKeys.TYPE to "theater"),
mapOf(SemanticKeys.TYPE to "whatever"),
)
)
assertEquals(1, events.size)
assertEquals("whatever", events.first().data[SemanticKeys.TYPE])
}

@Test
fun durationLonger() {
val events =
Expand Down

0 comments on commit a8c6d55

Please sign in to comment.