core/search/src/main/kotlin/io/klibs/core/search/PackageSearchRepositoryJdbc.kt [130:159]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - internal fun createWildcardSubqueries(rawQuery: String): Pair { assert(rawQuery.isNotBlank()) val words = rawQuery.trim().split("\\s+".toRegex()) val withSpecialChars = words.filter { it.hasSpecialCharacters() }.distinct() val withoutSpecialChars = (words.filter { !it.hasSpecialCharacters() } + withSpecialChars .flatMap { it.split(Regex("\\p{Punct}")) } .filter { it.isNotBlank() }).distinct() return Pair(withSpecialChars.map { it.normalizeSearchQuery() }.joinToQuery(), withoutSpecialChars.joinToQuery()) } private fun List.joinToQuery(): String = this.joinToString(separator = "|") { it.addWildcardPostfix() } private fun String.hasSpecialCharacters(): Boolean = contains(Regex("\\p{Punct}")) private fun String.normalizeSearchQuery(): String = escapeApostrophe().coverWithApostrophe() private fun String.coverWithApostrophe(): String = "'$this'" private fun String.escapeApostrophe(): String = replace("'", "''") private fun String.addWildcardPostfix(): String = "$this:*" override fun refreshIndex() { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - core/search/src/main/kotlin/io/klibs/core/search/ProjectSearchRepositoryJdbc.kt [236:265]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - internal fun createWildcardSubqueries(rawQuery: String): Pair { assert(rawQuery.isNotBlank()) val words = rawQuery.trim().split("\\s+".toRegex()) val withSpecialChars = words.filter { it.hasSpecialCharacters() }.distinct() val withoutSpecialChars = (words.filter { !it.hasSpecialCharacters() } + withSpecialChars .flatMap { it.split(Regex("\\p{Punct}")) } .filter { it.isNotBlank() }).distinct() return Pair(withSpecialChars.map { it.normalizeSearchQuery() }.joinToQuery(), withoutSpecialChars.joinToQuery()) } private fun List.joinToQuery(): String = this.joinToString(separator = "|") { it.addWildcardPostfix() } private fun String.hasSpecialCharacters(): Boolean = contains(Regex("\\p{Punct}")) private fun String.normalizeSearchQuery(): String = escapeApostrophe().coverWithApostrophe() private fun String.coverWithApostrophe(): String = "'$this'" private fun String.escapeApostrophe(): String = replace("'", "''") private fun String.addWildcardPostfix(): String = "$this:*" override fun refreshIndex() { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -