Implemented also searching for bank code in query for bank name and city as otherwise if bank code gets partly entered this would yield no search results
This commit is contained in:
parent
103968710c
commit
7d372c1ca0
|
@ -3,7 +3,7 @@ package net.dankito.banking.bankfinder
|
|||
|
||||
abstract class BankFinderBase : IBankFinder {
|
||||
|
||||
protected abstract fun findBankByNameOrCityForNonEmptyQuery(query: String): List<BankInfo>
|
||||
protected abstract fun findBankByNameBankCodeOrCityForNonEmptyQuery(query: String): List<BankInfo>
|
||||
|
||||
abstract fun searchBankByBic(bic: String): BankInfo?
|
||||
|
||||
|
@ -20,7 +20,7 @@ abstract class BankFinderBase : IBankFinder {
|
|||
return findBankByBankCode(query)
|
||||
}
|
||||
|
||||
return findBankByNameOrCityForNonEmptyQuery(query)
|
||||
return findBankByNameBankCodeOrCityForNonEmptyQuery(query)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,17 +19,17 @@ open class InMemoryBankFinder() : BankFinderBase(), IBankFinder {
|
|||
return getBankList().filter { it.bankCode.startsWith(query) }
|
||||
}
|
||||
|
||||
override fun findBankByNameOrCityForNonEmptyQuery(query: String): List<BankInfo> {
|
||||
override fun findBankByNameBankCodeOrCityForNonEmptyQuery(query: String): List<BankInfo> {
|
||||
val queryPartsLowerCase = query.toLowerCase().split(" ", "-")
|
||||
|
||||
return getBankList().filter { bankInfo ->
|
||||
checkIfAllQueryPartsMatchBankNameOrCity(queryPartsLowerCase, bankInfo)
|
||||
checkIfAllQueryPartsMatchBankNameBankCodeOrCity(queryPartsLowerCase, bankInfo)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun checkIfAllQueryPartsMatchBankNameOrCity(queryPartsLowerCase: List<String>, bankInfo: BankInfo): Boolean {
|
||||
protected open fun checkIfAllQueryPartsMatchBankNameBankCodeOrCity(queryPartsLowerCase: List<String>, bankInfo: BankInfo): Boolean {
|
||||
for (queryPartLowerCase in queryPartsLowerCase) {
|
||||
if (checkIfQueryMatchesBankNameOrCity(bankInfo, queryPartLowerCase) == false) {
|
||||
if (checkIfQueryMatchesBankNameBankCodeOrCity(bankInfo, queryPartLowerCase) == false) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,9 @@ open class InMemoryBankFinder() : BankFinderBase(), IBankFinder {
|
|||
return true
|
||||
}
|
||||
|
||||
protected open fun checkIfQueryMatchesBankNameOrCity(bankInfo: BankInfo, queryLowerCase: String): Boolean {
|
||||
protected open fun checkIfQueryMatchesBankNameBankCodeOrCity(bankInfo: BankInfo, queryLowerCase: String): Boolean {
|
||||
return bankInfo.name.toLowerCase().contains(queryLowerCase)
|
||||
|| bankInfo.bankCode.startsWith(queryLowerCase)
|
||||
|| bankInfo.city.toLowerCase().startsWith(queryLowerCase)
|
||||
|| bankInfo.branchesInOtherCities.any { it.toLowerCase().startsWith(queryLowerCase) }
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder {
|
|||
return getBanksFromQuery(luceneQuery)
|
||||
}
|
||||
|
||||
override fun findBankByNameOrCityForNonEmptyQuery(query: String): List<BankInfo> {
|
||||
override fun findBankByNameBankCodeOrCityForNonEmptyQuery(query: String): List<BankInfo> {
|
||||
bankFinderWhileUpdatingIndex?.let {
|
||||
return it.findBankByNameBankCodeOrCity(query)
|
||||
}
|
||||
|
@ -93,7 +93,9 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder {
|
|||
val luceneQuery = queries.createQueriesForSingleTerms(query.toLowerCase()) { singleTerm ->
|
||||
listOf(
|
||||
queries.fulltextQuery(BankInfoNameFieldName, singleTerm),
|
||||
queries.startsWith(BankInfoCityIndexedFieldName, singleTerm)
|
||||
queries.startsWith(BankInfoCityIndexedFieldName, singleTerm),
|
||||
queries.startsWith(BankInfoBankCodeFieldName, singleTerm)
|
||||
// TODO: add query for branchesInOtherCities
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -190,6 +192,8 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder {
|
|||
fields.storedField(BankInfoPostalCodeFieldName, bank.postalCode),
|
||||
fields.nullableStoredField(BankInfoPinTanServerAddressFieldName, bank.pinTanAddress),
|
||||
fields.nullableStoredField(BankInfoPinTanVersionFieldName, bank.pinTanVersion)
|
||||
|
||||
// TODO: index branchesInOtherCities
|
||||
)
|
||||
|
||||
bank.branchesInOtherCities.forEach { branchCity ->
|
||||
|
|
Loading…
Reference in New Issue