Implement find characters query
This commit is contained in:
parent
cfaff6c6b9
commit
a88b4d409d
@ -20,9 +20,15 @@ fun main() {
|
|||||||
val (shangWords, time3) = measureTimedValue {
|
val (shangWords, time3) = measureTimedValue {
|
||||||
sqliteDictionary.findWordsContaining(shang)
|
sqliteDictionary.findWordsContaining(shang)
|
||||||
}
|
}
|
||||||
|
val (characters, time4) = measureTimedValue {
|
||||||
|
val searchi = sqliteDictionary.search("師範大學", SearchMode.TRADITIONAL).first()
|
||||||
|
sqliteDictionary.findCharacters(searchi)
|
||||||
|
}
|
||||||
println(searchResults)
|
println(searchResults)
|
||||||
println(shangWords)
|
println(shangWords)
|
||||||
|
println(characters)
|
||||||
println(time)
|
println(time)
|
||||||
println(time2)
|
println(time2)
|
||||||
println(time3)
|
println(time3)
|
||||||
|
println(time4)
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,12 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val findCharacters = """
|
||||||
|
SELECT traditional, simplified, pinyin_with_tone_marks, pinyin_with_tone_numbers, zhuyin, definitions
|
||||||
|
FROM cedict
|
||||||
|
WHERE traditional IN (?)
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
override fun search(query: String, searchMode: SearchMode) = when (searchMode) {
|
override fun search(query: String, searchMode: SearchMode) = when (searchMode) {
|
||||||
SearchMode.PINYIN -> searchPinyin(query)
|
SearchMode.PINYIN -> searchPinyin(query)
|
||||||
SearchMode.SIMPLIFIED -> searchSimplified(query)
|
SearchMode.SIMPLIFIED -> searchSimplified(query)
|
||||||
@ -73,7 +79,16 @@ class SqliteDictionary(private val connection: Connection) : Dictionary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> {
|
override fun findCharacters(entry: DictionaryEntry): List<DictionaryEntry> {
|
||||||
return emptyList()
|
val characterList = entry.traditional
|
||||||
|
.split("")
|
||||||
|
.filter { it.isNotBlank() }
|
||||||
|
.joinToString(",") { "'$it'" }
|
||||||
|
|
||||||
|
val query = findCharacters.replace("?", characterList)
|
||||||
|
|
||||||
|
val resultSet: ResultSet = connection.createStatement().executeQuery(query)
|
||||||
|
|
||||||
|
return resultSet.toListOfDictionaryEntries()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchSimplified(query: String): List<DictionaryEntry> {
|
private fun searchSimplified(query: String): List<DictionaryEntry> {
|
||||||
|
Loading…
Reference in New Issue
Block a user