Skip to content

Commit

Permalink
Add support for case-insensitive search for UTF strings. (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
roundhill authored Sep 5, 2018
1 parent 9e378b1 commit 877d4e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,17 @@ public void testFullTextSearching()
note.setContent("lorem ipsum dolor whatever");
note.addTags("literature");

note = mBucket.newObject("ftsearch4");
note.setContent("Бабушка means Grandmother.");
note.save();

assertEquals(1, mBucket.query().where(new Query.FullTextMatch("town hall")).count());

assertEquals(2, mBucket.query().where(new Query.FullTextMatch("two")).count());

assertEquals(1, mBucket.query().where(new Query.FullTextMatch("tags:two")).count());

assertEquals(1, mBucket.query().where(new Query.FullTextMatch("бабушка")).count());
}

public void testFullTextSnippet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ private void setupFullText() {
if (rebuild) {
mDatabase.execSQL(String.format(Locale.US, "DROP TABLE IF EXISTS `%s`", tableName));
StringBuilder fields = new StringBuilder();
if (supportsUnicodeFullText()) {
// Add unicode case-insensitive search support
fields.append("tokenize=unicode61, ");
}
for (String key : keys) {
fields.append("`");
fields.append(key);
Expand Down Expand Up @@ -630,15 +634,19 @@ private void compileQuery() {
}

// See issue #150, Android < 15 can't use distinct in full text queries
public static boolean supportsDistinct(boolean fullTextQuery) {
static boolean supportsDistinct(boolean fullTextQuery) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return true;
}

// Otherwise only use distinct if it's not a full text query
return !fullTextQuery;
}

// Android < 21 can't use `unicode61` SQLite tokenizer
static boolean supportsUnicodeFullText() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}


Expand Down

0 comments on commit 877d4e7

Please sign in to comment.