Skip to content

Commit 877d4e7

Browse files
authored
Add support for case-insensitive search for UTF strings. (#199)
Ref: Automattic/simplenote-android#278
1 parent 9e378b1 commit 877d4e7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Simperium/src/androidTestSupport/java/com/simperium/PersistentStoreTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,17 @@ public void testFullTextSearching()
362362
note.setContent("lorem ipsum dolor whatever");
363363
note.addTags("literature");
364364

365+
note = mBucket.newObject("ftsearch4");
366+
note.setContent("Бабушка means Grandmother.");
367+
note.save();
368+
365369
assertEquals(1, mBucket.query().where(new Query.FullTextMatch("town hall")).count());
366370

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

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

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

373378
public void testFullTextSnippet()

Simperium/src/main/java/com/simperium/android/PersistentStore.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ private void setupFullText() {
275275
if (rebuild) {
276276
mDatabase.execSQL(String.format(Locale.US, "DROP TABLE IF EXISTS `%s`", tableName));
277277
StringBuilder fields = new StringBuilder();
278+
if (supportsUnicodeFullText()) {
279+
// Add unicode case-insensitive search support
280+
fields.append("tokenize=unicode61, ");
281+
}
278282
for (String key : keys) {
279283
fields.append("`");
280284
fields.append(key);
@@ -630,15 +634,19 @@ private void compileQuery() {
630634
}
631635

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

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

639643
// Otherwise only use distinct if it's not a full text query
640644
return !fullTextQuery;
645+
}
641646

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

644652

0 commit comments

Comments
 (0)