Implemented that if an integer is enter only for bank code is search, otherwise only for bank name and city
This commit is contained in:
parent
ed5d4bb241
commit
b18a9a04f4
|
@ -14,6 +14,22 @@ abstract class BankFinderBase : IBankFinder {
|
|||
}
|
||||
|
||||
|
||||
protected abstract fun findBankByNameOrCityForNonEmptyQuery(query: String): List<BankInfo>
|
||||
|
||||
|
||||
override fun findBankByNameBankCodeOrCity(query: String?): List<BankInfo> {
|
||||
if (query.isNullOrBlank()) {
|
||||
return getBankList()
|
||||
}
|
||||
|
||||
if (query.toIntOrNull() != null) { // if query is an integer, then it can only be an bank code, but not a bank name or city
|
||||
return findBankByBankCode(query)
|
||||
}
|
||||
|
||||
return findBankByNameOrCityForNonEmptyQuery(query)
|
||||
}
|
||||
|
||||
|
||||
protected open fun loadBankListFile(): List<BankInfo> {
|
||||
try {
|
||||
val bankListString = readBankListFile()
|
||||
|
|
|
@ -21,22 +21,17 @@ open class InMemoryBankFinder() : BankFinderBase(), IBankFinder {
|
|||
return getBankList().filter { it.bankCode.startsWith(query) }
|
||||
}
|
||||
|
||||
override fun findBankByNameBankCodeOrCity(query: String?): List<BankInfo> {
|
||||
if (query.isNullOrEmpty()) {
|
||||
return getBankList()
|
||||
}
|
||||
|
||||
val queryLowerCase = query.toLowerCase()
|
||||
val queryPartsLowerCase = queryLowerCase.split(" ")
|
||||
override fun findBankByNameOrCityForNonEmptyQuery(query: String): List<BankInfo> {
|
||||
val queryPartsLowerCase = query.toLowerCase().split(" ")
|
||||
|
||||
return getBankList().filter { bankInfo ->
|
||||
checkIfAllQueryPartsMatchBank(queryPartsLowerCase, bankInfo)
|
||||
checkIfAllQueryPartsMatchBankNameOrCity(queryPartsLowerCase, bankInfo)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun checkIfAllQueryPartsMatchBank(queryPartsLowerCase: List<String>, bankInfo: BankInfo): Boolean {
|
||||
protected open fun checkIfAllQueryPartsMatchBankNameOrCity(queryPartsLowerCase: List<String>, bankInfo: BankInfo): Boolean {
|
||||
for (queryPartLowerCase in queryPartsLowerCase) {
|
||||
if (checkIfQueryMatchesBank(bankInfo, queryPartLowerCase) == false) {
|
||||
if (checkIfQueryMatchesBankNameOrCity(bankInfo, queryPartLowerCase) == false) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +39,8 @@ open class InMemoryBankFinder() : BankFinderBase(), IBankFinder {
|
|||
return true
|
||||
}
|
||||
|
||||
protected open fun checkIfQueryMatchesBank(bankInfo: BankInfo, queryLowerCase: String): Boolean {
|
||||
protected open fun checkIfQueryMatchesBankNameOrCity(bankInfo: BankInfo, queryLowerCase: String): Boolean {
|
||||
return bankInfo.name.toLowerCase().contains(queryLowerCase)
|
||||
|| bankInfo.bankCode.startsWith(queryLowerCase)
|
||||
|| bankInfo.city.toLowerCase().contains(queryLowerCase)
|
||||
}
|
||||
|
||||
|
|
|
@ -90,19 +90,14 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder {
|
|||
return getBanksFromQuery(luceneQuery)
|
||||
}
|
||||
|
||||
override fun findBankByNameBankCodeOrCity(query: String?): List<BankInfo> {
|
||||
override fun findBankByNameOrCityForNonEmptyQuery(query: String): List<BankInfo> {
|
||||
bankFinderWhileUpdatingIndex?.let {
|
||||
return it.findBankByNameBankCodeOrCity(query)
|
||||
}
|
||||
|
||||
if (query.isNullOrBlank()) {
|
||||
return getBankList()
|
||||
}
|
||||
|
||||
val luceneQuery = queries.createQueriesForSingleTerms(query.toLowerCase()) { singleTerm ->
|
||||
listOf(
|
||||
queries.fulltextQuery(BankInfoNameFieldName, singleTerm),
|
||||
queries.startsWith(BankInfoBankCodeFieldName, singleTerm),
|
||||
queries.contains(BankInfoCityIndexedFieldName, singleTerm)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue