I'm looking for a efficient way to find items in a table (lets say Location) with a column "short_name". In my Kotlin code I have a couple of filter queries and in two of them a property with a list of approx 1000 names as substrings, so I need to look for substrings and it should be case-insensitive.
I found a couple solutions, but all of them take a lot of time.
Data model: filter.shortNames: List<String>? = null
Solution 1 - "fold":
filter.shortNames?. let {
val first = it.first()
condition = condition.and(
it.minus(first).fold(LOCATION.SHORTNAME.likeIgnoreCase("%$first%")) { con: Condition, name: String ->
con.or(LOCATION.KEY.likeIgnoreCase("%$name%"))
}
)
}
Solution 2 - "like any":
filter.shortNames?. let {
condition = condition.and(DSL.lower(LOCATION.SHORTNAME).like(DSL.any(*it.map { e -> "%${e.lowercase()}%" }.toTypedArray())))
}
Like I said, the requests with both solutions take around 7 sec for all filter-queries. And the pain is definitely the condition with the short_name.
I couldn't find a better solution, which reduces the response time significantly. So I hope for help here.
Thank you guys.