Optimize imports, disallow wildcard imports because of klint, run linter
This commit is contained in:
@@ -7,8 +7,10 @@ import exh.metadata.sql.tables.SearchTitleTable
|
||||
class SearchEngine {
|
||||
private val queryCache = mutableMapOf<String, List<QueryComponent>>()
|
||||
|
||||
fun textToSubQueries(namespace: String?,
|
||||
component: Text?): Pair<String, List<String>>? {
|
||||
fun textToSubQueries(
|
||||
namespace: String?,
|
||||
component: Text?
|
||||
): Pair<String, List<String>>? {
|
||||
val maybeLenientComponent = component?.let {
|
||||
if (!it.exact)
|
||||
it.asLenientTagQueries()
|
||||
@@ -22,20 +24,20 @@ class SearchEngine {
|
||||
"${SearchTagTable.TABLE}.${SearchTagTable.COL_NAME} LIKE ?"
|
||||
}.joinToString(separator = " OR ", prefix = "(", postfix = ")") to params
|
||||
}
|
||||
return if(namespace != null) {
|
||||
return if (namespace != null) {
|
||||
var query = """
|
||||
(SELECT ${SearchTagTable.COL_MANGA_ID} AS $COL_MANGA_ID FROM ${SearchTagTable.TABLE}
|
||||
WHERE ${SearchTagTable.COL_NAMESPACE} IS NOT NULL
|
||||
AND ${SearchTagTable.COL_NAMESPACE} LIKE ?
|
||||
""".trimIndent()
|
||||
val params = mutableListOf(escapeLike(namespace))
|
||||
if(componentTagQuery != null) {
|
||||
if (componentTagQuery != null) {
|
||||
query += "\n AND ${componentTagQuery.first}"
|
||||
params += componentTagQuery.second
|
||||
}
|
||||
|
||||
"$query)" to params
|
||||
} else if(component != null) {
|
||||
} else if (component != null) {
|
||||
// Match title + tags
|
||||
val tagQuery = """
|
||||
SELECT ${SearchTagTable.COL_MANGA_ID} AS $COL_MANGA_ID FROM ${SearchTagTable.TABLE}
|
||||
@@ -59,27 +61,27 @@ class SearchEngine {
|
||||
val include = mutableListOf<Pair<String, List<String>>>()
|
||||
val exclude = mutableListOf<Pair<String, List<String>>>()
|
||||
|
||||
for(component in q) {
|
||||
val query = if(component is Text) {
|
||||
for (component in q) {
|
||||
val query = if (component is Text) {
|
||||
textToSubQueries(null, component)
|
||||
} else if(component is Namespace) {
|
||||
if(component.namespace == "uploader") {
|
||||
} else if (component is Namespace) {
|
||||
if (component.namespace == "uploader") {
|
||||
wheres += "meta.${SearchMetadataTable.COL_UPLOADER} LIKE ?"
|
||||
whereParams += component.tag!!.rawTextEscapedForLike()
|
||||
null
|
||||
} else {
|
||||
if(component.tag!!.components.size > 0) {
|
||||
//Match namespace + tags
|
||||
if (component.tag!!.components.size > 0) {
|
||||
// Match namespace + tags
|
||||
textToSubQueries(component.namespace, component.tag)
|
||||
} else {
|
||||
//Perform namespace search
|
||||
// Perform namespace search
|
||||
textToSubQueries(component.namespace, null)
|
||||
}
|
||||
}
|
||||
} else error("Unknown query component!")
|
||||
|
||||
if(query != null) {
|
||||
(if(component.excluded) exclude else include) += query
|
||||
if (query != null) {
|
||||
(if (component.excluded) exclude else include) += query
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,14 +99,13 @@ class SearchEngine {
|
||||
completeParams += pair.second
|
||||
}
|
||||
|
||||
|
||||
exclude.forEach {
|
||||
wheres += """
|
||||
(meta.${SearchMetadataTable.COL_MANGA_ID} NOT IN ${it.first})
|
||||
""".trimIndent()
|
||||
whereParams += it.second
|
||||
}
|
||||
if(wheres.isNotEmpty()) {
|
||||
if (wheres.isNotEmpty()) {
|
||||
completeParams += whereParams
|
||||
baseQuery += "\nWHERE\n"
|
||||
baseQuery += wheres.joinToString("\nAND\n")
|
||||
@@ -126,7 +127,7 @@ class SearchEngine {
|
||||
var nextIsExact = false
|
||||
|
||||
fun flushText() {
|
||||
if(queuedRawText.isNotEmpty()) {
|
||||
if (queuedRawText.isNotEmpty()) {
|
||||
queuedText += StringTextComponent(queuedRawText.toString())
|
||||
queuedRawText.setLength(0)
|
||||
}
|
||||
@@ -150,24 +151,24 @@ class SearchEngine {
|
||||
}
|
||||
}
|
||||
|
||||
for(char in query.toLowerCase()) {
|
||||
if(char == '"') {
|
||||
for (char in query.toLowerCase()) {
|
||||
if (char == '"') {
|
||||
inQuotes = !inQuotes
|
||||
} else if(enableWildcard && (char == '?' || char == '_')) {
|
||||
} else if (enableWildcard && (char == '?' || char == '_')) {
|
||||
flushText()
|
||||
queuedText.add(SingleWildcard(char.toString()))
|
||||
} else if(enableWildcard && (char == '*' || char == '%')) {
|
||||
} else if (enableWildcard && (char == '*' || char == '%')) {
|
||||
flushText()
|
||||
queuedText.add(MultiWildcard(char.toString()))
|
||||
} else if(char == '-') {
|
||||
} else if (char == '-') {
|
||||
nextIsExcluded = true
|
||||
} else if(char == '$') {
|
||||
} else if (char == '$') {
|
||||
nextIsExact = true
|
||||
} else if(char == ':') {
|
||||
} else if (char == ':') {
|
||||
flushText()
|
||||
var flushed = flushToText().rawTextOnly()
|
||||
//Map tag aliases
|
||||
flushed = when(flushed) {
|
||||
// Map tag aliases
|
||||
flushed = when (flushed) {
|
||||
"a" -> "artist"
|
||||
"c", "char" -> "character"
|
||||
"f" -> "female"
|
||||
@@ -179,7 +180,7 @@ class SearchEngine {
|
||||
else -> flushed
|
||||
}
|
||||
namespace = Namespace(flushed, null)
|
||||
} else if(char == ' ' && !inQuotes) {
|
||||
} else if (char == ' ' && !inQuotes) {
|
||||
flushAll()
|
||||
} else {
|
||||
queuedRawText.append(char)
|
||||
@@ -197,7 +198,6 @@ class SearchEngine {
|
||||
return string.replace("\\", "\\\\")
|
||||
.replace("_", "\\_")
|
||||
.replace("%", "\\%")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user