Skip to content

Commit

Permalink
tokenize equipment search
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Nov 22, 2024
1 parent a50bb81 commit 9fe345f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Habitica/res/drawable/search_background.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 9fe345f

Please sign in to comment.