Merge branch 'fix-560--searching-only-whitespace' into 'master'

Fix 560  (searching only whitespace)

When no keywords to search, use an empty query selection that evaluates to "1".

This means that instead of building invalid SQL such as `WHERE (() OR ())` it
will build `WHERE((1) OR (1))` which, while non-optimal, is at least valid.
In fact, I'm not even sure that it is non optimal because I'd hope the sqlite
query optimizer is able to realise that `1 OR 1` is effectively a no-op.

Fixes issue #560.

See merge request !201
This commit is contained in:
Daniel Martí 2016-02-03 21:31:15 +00:00
commit 29b6b261a2
3 changed files with 33 additions and 8 deletions

View File

@ -1,3 +1,7 @@
### Upcoming Release
* Fix bug when entering only a space into the search dialog.
### 0.98 (2015-02-02)
* Add opt-in crash reporting via ACRA

View File

@ -614,15 +614,14 @@ public class AppProvider extends FDroidProvider {
}
private AppQuerySelection querySearch(String query) {
final String[] columns = {
getTableName() + ".id",
getTableName() + ".name",
getTableName() + ".summary",
getTableName() + ".description",
};
// Remove duplicates, surround in % for wildcard searching
// Put in a Set to remove duplicates
final Set<String> keywordSet = new HashSet<>(Arrays.asList(query.split("\\s")));
if (keywordSet.size() == 0) {
return new AppQuerySelection();
}
// Surround each keyword in % for wildcard searching
final String[] keywords = new String[keywordSet.size()];
int iKeyword = 0;
for (final String keyword : keywordSet) {
@ -630,6 +629,13 @@ public class AppProvider extends FDroidProvider {
iKeyword++;
}
final String[] columns = {
getTableName() + ".id",
getTableName() + ".name",
getTableName() + ".summary",
getTableName() + ".description",
};
// Build selection string and fill out keyword arguments
final StringBuilder selection = new StringBuilder();
final String[] selectionKeywords = new String[columns.length * keywords.length];

View File

@ -58,7 +58,22 @@ public class AppListFragmentPagerAdapter extends FragmentPagerAdapter {
return parent.getString(R.string.tab_updates_count, updateCount);
}
/**
* Changing the search query is quite an expensive operation, so this does some rudimentary
* checking to see if the two queries are meaningfully different. At present, it trims the
* strings and does a case insensitive comparison.
*/
private boolean isSearchQuerySame(String newQuery) {
String oldValueTrimmed = searchQuery == null ? "" : searchQuery.trim();
String newValueTrimmed = newQuery == null ? "" : newQuery.trim();
return oldValueTrimmed.equalsIgnoreCase(newValueTrimmed);
}
public void updateSearchQuery(@Nullable String query) {
if (isSearchQuerySame(query)) {
return;
}
searchQuery = query;
for (AppListFragment fragment : registeredFragments) {
if (fragment != null) {