Add preference for fuzzy search, improve search efficiency

This commit is contained in:
Jan Koll 2025-06-26 21:16:14 +02:00
parent 59885133f8
commit 19e40bb1b7
6 changed files with 15 additions and 11 deletions

View file

@ -67,28 +67,23 @@ class AppFilter(
val r: MutableList<AbstractDetailedAppInfo> = ArrayList()
val appsSecondary: MutableList<AbstractDetailedAppInfo> = ArrayList()
val normalizedQuery: String = normalize(query)
val subsequentResult: MutableList<AbstractDetailedAppInfo> = mutableListOf();
val occurrences: MutableMap<AbstractDetailedAppInfo, Int> = mutableMapOf();
for (item in apps) {
val itemLabel: String = normalize(item.getCustomLabel(context))
if (itemLabel.startsWith(normalizedQuery)) {
appsSecondary.add(item);
}
// todo: maybe re-enable this with preferences? I think it's a bit clunky with the "fuzzy"-search though
/*else if (itemLabel.contains(normalizedQuery)) {
} else if (itemLabel.contains(normalizedQuery) && !LauncherPreferences.functionality().searchFuzzy()) {
appsSecondary.add(item)
}*/
}
if (appsSecondary.size != 1) {
val subsequentResult: MutableList<AbstractDetailedAppInfo> = mutableListOf();
val occurrences: MutableMap<AbstractDetailedAppInfo, Int> = mutableMapOf();
for (item in apps) {
if (appsSecondary.contains(item)) continue;
val itemLabel: String = normalize(item.getCustomLabel(context))
} else {
if (isSubsequent(itemLabel, normalizedQuery)) {
subsequentResult.add(item)
}
occurrences[item] = countOccurrences(itemLabel, normalizedQuery)
}
}
if (LauncherPreferences.functionality().searchFuzzy() && appsSecondary.size != 1) {
if (subsequentResult.isNotEmpty()) {
appsSecondary.addAll(subsequentResult)
} else {

View file

@ -75,6 +75,7 @@ import eu.jonahbauer.android.preference.annotations.Preferences;
@Preference(name = "search_web", type = boolean.class, description = "false"),
@Preference(name = "search_auto_open_keyboard", type = boolean.class, defaultValue = "true"),
@Preference(name = "search_auto_close_keyboard", type = boolean.class, defaultValue = "false"),
@Preference(name = "search_fuzzy", type = boolean.class, defaultValue = "true"),
}),
@PreferenceGroup(name = "enabled_gestures", prefix = "settings_enabled_gestures_", suffix = "_key", value = {
@Preference(name = "double_swipe", type = boolean.class, defaultValue = "true"),

View file

@ -309,4 +309,5 @@
<string name="list_other_list_private_space">Privater Bereich</string>
<string name="list_other_track_play_pause">Musik: Wiedergabe / Pause</string>
<string name="settings_list_reverse_layout">Appliste umkehren</string>
<string name="settings_functionality_search_fuzzy">Fuzzy-Suche verwenden</string>
</resources>

View file

@ -148,6 +148,7 @@
<string name="settings_enabled_gestures_edge_swipe_edge_width_key" translatable="false">enabled_gestures.edge_actions.edge_width</string>
<string name="settings_functionality_search_auto_launch_key" translatable="false">functionality.search_auto_launch</string>
<string name="settings_functionality_search_web_key" translatable="false">functionality.search_web</string>
<string name="settings_functionality_search_fuzzy_key" translatable="false">functionality.search_fuzzy</string>
<string name="settings_functionality_search_auto_open_keyboard_key" translatable="false">functionality.search_auto_keyboard</string>
<string name="settings_functionality_search_auto_close_keyboard_key" translatable="false">functionality.search_auto_close_keyboard</string>

View file

@ -456,4 +456,5 @@
<string name="content_description_navigate_next">Navigate next</string>
<string name="content_description_lock">Lock</string>
<string name="content_description_settings_actions_row_button_remove">Remove binding</string>
<string name="settings_functionality_search_fuzzy">Use fuzzy search</string>
</resources>

View file

@ -100,6 +100,11 @@
android:defaultValue="false"
android:summary="@string/settings_functionality_search_web_summary"
/>
<SwitchPreference
android:key="@string/settings_functionality_search_fuzzy_key"
android:title="@string/settings_functionality_search_fuzzy"
android:defaultValue="true"
/>
<SwitchPreference
android:key="@string/settings_functionality_search_auto_open_keyboard_key"
android:defaultValue="true"