mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-14 18:24:57 +00:00
android: Improve searches with one character
The Jaccard algorithm is great for searches with 2 or more characters but nothing is returned for searches with one character. To get around this, just search with JaroWinkler for single character searches.
This commit is contained in:
parent
0cbae33790
commit
bfb4e3bcaa
1 changed files with 2 additions and 1 deletions
|
@ -19,6 +19,7 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import info.debatty.java.stringsimilarity.Jaccard
|
import info.debatty.java.stringsimilarity.Jaccard
|
||||||
|
import info.debatty.java.stringsimilarity.JaroWinkler
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.YuzuApplication
|
import org.yuzu.yuzu_emu.YuzuApplication
|
||||||
import org.yuzu.yuzu_emu.adapters.GameAdapter
|
import org.yuzu.yuzu_emu.adapters.GameAdapter
|
||||||
|
@ -150,7 +151,7 @@ class SearchFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val searchTerm = binding.searchText.text.toString().lowercase(Locale.getDefault())
|
val searchTerm = binding.searchText.text.toString().lowercase(Locale.getDefault())
|
||||||
val searchAlgorithm = Jaccard(2)
|
val searchAlgorithm = if (searchTerm.length > 1) Jaccard(2) else JaroWinkler()
|
||||||
val sortedList: List<Game> = filteredList.mapNotNull { game ->
|
val sortedList: List<Game> = filteredList.mapNotNull { game ->
|
||||||
val title = game.title.lowercase(Locale.getDefault())
|
val title = game.title.lowercase(Locale.getDefault())
|
||||||
val score = searchAlgorithm.similarity(searchTerm, title)
|
val score = searchAlgorithm.similarity(searchTerm, title)
|
||||||
|
|
Loading…
Reference in a new issue