Ignore leading and trailing whitespaces in search keywords

As reported in #58
This commit is contained in:
Daniel Martí 2015-03-30 17:41:35 +02:00
parent 85d7752d0a
commit d22c714dbd
3 changed files with 13 additions and 4 deletions

View File

@ -497,14 +497,14 @@ public class AppProvider extends FDroidProvider {
}
private AppQuerySelection querySearch(String keywords) {
keywords = "%" + keywords + "%";
keywords = "%" + cleanQueryKeywords(keywords) + "%";
String selection =
"fdroid_app.id like ? OR " +
"fdroid_app.name like ? OR " +
"fdroid_app.summary like ? OR " +
"fdroid_app.description like ? ";
String[] args = new String[] { keywords, keywords, keywords, keywords};
return new AppQuerySelection(selection, args);
return new AppQuerySelection(selection,
new String[] { keywords, keywords, keywords, keywords });
}
private AppQuerySelection querySingle(String id) {

View File

@ -142,5 +142,12 @@ public abstract class FDroidProvider extends ContentProvider {
}
}
}
protected static String cleanQueryKeywords(String keywords) {
if (keywords == null) {
return null;
}
return keywords.trim();
}
}

View File

@ -128,7 +128,9 @@ public class InstalledAppProvider extends FDroidProvider {
}
private QuerySelection querySearch(String keywords) {
return new QuerySelection("applicationLabel LIKE ?", new String[]{ "%" + keywords + "%" });
keywords = "%" + cleanQueryKeywords(keywords) + "%";
return new QuerySelection("applicationLabel LIKE ?",
new String[]{ keywords });
}
@Override