Skip to content

Commit d010cec

Browse files
committed
Fix adding hamming matches
Only add hamming matches when they're not in the list of exact matches already.
1 parent fa5b571 commit d010cec

File tree

1 file changed

+8
-9
lines changed
  • app/src/main/java/de/markusfisch/android/pielauncher/content

1 file changed

+8
-9
lines changed

app/src/main/java/de/markusfisch/android/pielauncher/content/AppMenu.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,26 @@ public List<AppIcon> filterAppsBy(Context context, String query) {
170170
String subject = getSubject(item, appIcon, defaultLocale);
171171
boolean add = false;
172172
switch (strategy) {
173-
case Preferences.SEARCH_STRICTNESS_STARTS_WITH:
174-
add = subject.startsWith(query);
175-
break;
173+
// HAMMING includes CONTAINS for historical reasons.
176174
case Preferences.SEARCH_STRICTNESS_HAMMING:
177-
if (hammingDistance(subject, query) < 2) {
178-
hamming.add(appIcon);
179-
}
180-
// Fall through because HAMMING includes CONTAINS
181-
// for historical reasons.
182175
case Preferences.SEARCH_STRICTNESS_CONTAINS:
183176
add = subject.contains(query);
184177
break;
178+
case Preferences.SEARCH_STRICTNESS_STARTS_WITH:
179+
add = subject.startsWith(query);
180+
break;
185181
}
186182
if (add) {
187183
list.add(appIcon);
184+
} else if (strategy == Preferences.SEARCH_STRICTNESS_HAMMING &&
185+
hammingDistance(subject, query) < 2) {
186+
hamming.add(appIcon);
188187
}
189188
}
190189
}
191190

192191
Collections.sort(list, appLabelComparator);
193-
if (strategy == Preferences.SEARCH_STRICTNESS_HAMMING) {
192+
if (!hamming.isEmpty()) {
194193
// Only append hamming matches as they're less likely
195194
// as good as exact matches.
196195
Collections.sort(hamming, appLabelComparator);

0 commit comments

Comments
 (0)