diff --git a/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt b/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt index f6dc7a89..abc7999b 100644 --- a/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt +++ b/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/BankFinderBase.kt @@ -3,7 +3,7 @@ package net.dankito.banking.bankfinder abstract class BankFinderBase : IBankFinder { - protected abstract fun findBankByNameOrCityForNonEmptyQuery(query: String): List + protected abstract fun findBankByNameBankCodeOrCityForNonEmptyQuery(query: String): List abstract fun searchBankByBic(bic: String): BankInfo? @@ -20,7 +20,7 @@ abstract class BankFinderBase : IBankFinder { return findBankByBankCode(query) } - return findBankByNameOrCityForNonEmptyQuery(query) + return findBankByNameBankCodeOrCityForNonEmptyQuery(query) } diff --git a/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt b/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt index 1c46d46e..beeb10bf 100644 --- a/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt +++ b/tools/BankFinder/src/commonMain/kotlin/net/dankito/banking/bankfinder/InMemoryBankFinder.kt @@ -19,17 +19,17 @@ open class InMemoryBankFinder() : BankFinderBase(), IBankFinder { return getBankList().filter { it.bankCode.startsWith(query) } } - override fun findBankByNameOrCityForNonEmptyQuery(query: String): List { + override fun findBankByNameBankCodeOrCityForNonEmptyQuery(query: String): List { val queryPartsLowerCase = query.toLowerCase().split(" ", "-") return getBankList().filter { bankInfo -> - checkIfAllQueryPartsMatchBankNameOrCity(queryPartsLowerCase, bankInfo) + checkIfAllQueryPartsMatchBankNameBankCodeOrCity(queryPartsLowerCase, bankInfo) } } - protected open fun checkIfAllQueryPartsMatchBankNameOrCity(queryPartsLowerCase: List, bankInfo: BankInfo): Boolean { + protected open fun checkIfAllQueryPartsMatchBankNameBankCodeOrCity(queryPartsLowerCase: List, 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) } } diff --git a/tools/LuceneBankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt b/tools/LuceneBankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt index 540bf0d3..5c3f4334 100644 --- a/tools/LuceneBankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt +++ b/tools/LuceneBankFinder/src/main/kotlin/net/dankito/banking/bankfinder/LuceneBankFinder.kt @@ -85,7 +85,7 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder { return getBanksFromQuery(luceneQuery) } - override fun findBankByNameOrCityForNonEmptyQuery(query: String): List { + override fun findBankByNameBankCodeOrCityForNonEmptyQuery(query: String): List { 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 ->