tokenize equipment search

This commit is contained in:
Phillip Thelen 2024-11-22 16:23:46 +01:00
parent a50bb81493
commit 9fe345f72e
2 changed files with 12 additions and 2 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="6dp" />
<corners android:radius="12dp" />
<solid android:color="@color/window_background" />
</shape>

View file

@ -135,7 +135,17 @@ class EquipmentDetailFragment :
if (query.isNullOrBlank()) {
return@combine equipment
}
equipment.filter { it.text.contains(query, true) || it.notes.contains(query, true) }
val tokens = query.split(" ")
val tokenCount = tokens.size
equipment.filter {
var matchCount = 0
for (token in tokens) {
if (it.text.contains(token, true) || it.notes.contains(token, true)) {
matchCount += 1
}
}
return@filter matchCount == tokenCount
}
}
.map { it.sortedBy { equipment -> equipment.text } }
.collect { adapter.data = it }