Implemented multi part query so that search terms can be separated by white space, e. g. 'Berliner Sparkasse'
This commit is contained in:
parent
2df51c37ae
commit
00e2a7fa92
|
@ -29,14 +29,29 @@ open class BankFinder {
|
|||
}
|
||||
|
||||
val queryLowerCase = query.toLowerCase()
|
||||
val queryPartsLowerCase = queryLowerCase.split(" ")
|
||||
|
||||
return getBankList().filter {
|
||||
it.name.toLowerCase().contains(queryLowerCase)
|
||||
|| it.bankCode.startsWith(query)
|
||||
|| it.city.toLowerCase().contains(queryLowerCase)
|
||||
return getBankList().filter { bankInfo ->
|
||||
checkIfAllQueryPartsMatchBank(queryPartsLowerCase, bankInfo)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun checkIfAllQueryPartsMatchBank(queryPartsLowerCase: List<String>, bankInfo: BankInfo): Boolean {
|
||||
for (queryPartLowerCase in queryPartsLowerCase) {
|
||||
if (checkIfQueryMatchesBank(bankInfo, queryPartLowerCase) == false) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
protected open fun checkIfQueryMatchesBank(bankInfo: BankInfo, queryLowerCase: String): Boolean {
|
||||
return bankInfo.name.toLowerCase().contains(queryLowerCase)
|
||||
|| bankInfo.bankCode.startsWith(queryLowerCase)
|
||||
|| bankInfo.city.toLowerCase().contains(queryLowerCase)
|
||||
}
|
||||
|
||||
|
||||
open fun getBankList(): List<BankInfo> {
|
||||
bankListField?.let {
|
||||
|
|
|
@ -19,8 +19,9 @@ class BankFinderTest {
|
|||
assertThat(result[0].name).isEqualTo("Bundesbank")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun findBankByNameBankCodeOrCity_starnberg() {
|
||||
fun findBankByNameBankCodeOrCity_Starnberg_MultipleResults() {
|
||||
|
||||
// when
|
||||
val result = underTest.findBankByNameBankCodeOrCity("starnberg")
|
||||
|
@ -30,14 +31,39 @@ class BankFinderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun findBankByNameBankCodeOrCity_mizUh() {
|
||||
fun findBankByNameBankCodeOrCity_mizUh_SingleResult() {
|
||||
|
||||
// when
|
||||
val result = underTest.findBankByNameBankCodeOrCity("mizUh")
|
||||
|
||||
// then
|
||||
assertThat(result).hasSize(1)
|
||||
assertThat(result[0].name).isEqualTo("Mizuho Bank Filiale Düsseldorf")
|
||||
|
||||
assertThat(result.first().name).isEqualTo("Mizuho Bank Filiale Düsseldorf")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findBankByNameBankCodeOrCity_MultiPartsQuery_BerlinSparkas() {
|
||||
|
||||
// when
|
||||
val result = underTest.findBankByNameBankCodeOrCity("Berlin Sparkas")
|
||||
|
||||
// then
|
||||
assertThat(result).hasSize(3)
|
||||
|
||||
assertThat(result.first().name).isEqualTo("Landesbank Berlin - Berliner Sparkasse")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findBankByNameBankCodeOrCity_MultiPartsQuery_SparkasBerlin() {
|
||||
|
||||
// when
|
||||
val result = underTest.findBankByNameBankCodeOrCity("Sparkas Berlin")
|
||||
|
||||
// then
|
||||
assertThat(result).hasSize(3)
|
||||
|
||||
assertThat(result.first().name).isEqualTo("Landesbank Berlin - Berliner Sparkasse")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue