mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Allow searching for words with apostrophes.
Previously, because apostrophes were 'banned' characters, searching for them wouldn't work. That meant you couldn't find words like "I'm". Now we just replace the apostrophe with a space and things "just work" because of the nature of SQLite tokenization and prefix queries.
This commit is contained in:
parent
afec9e8cb0
commit
5f99470226
@ -119,6 +119,9 @@ class SearchRepository {
|
||||
/**
|
||||
* Unfortunately {@link DatabaseUtils#sqlEscapeString(String)} is not sufficient for our purposes.
|
||||
* MATCH queries have a separate format of their own that disallow most "special" characters.
|
||||
*
|
||||
* Also, SQLite can't search for apostrophes, meaning we can't normally find words like "I'm".
|
||||
* However, if we replace the apostrophe with a space, then the query will find the match.
|
||||
*/
|
||||
private String sanitizeQuery(@NonNull String query) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
@ -127,6 +130,8 @@ class SearchRepository {
|
||||
char c = query.charAt(i);
|
||||
if (!BANNED_CHARACTERS.contains(c)) {
|
||||
out.append(c);
|
||||
} else if (c == '\'') {
|
||||
out.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user