Skip to content

Commit

Permalink
Upgrade to FTS4 with unicode61
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Oct 21, 2023
1 parent 14ec1af commit bc5ddeb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,11 @@ CREATE VIEW Item_Path AS
join Category c ON i.category = c._id
;


CREATE VIRTUAL TABLE Search USING FTS3 (
-- FTS4 available since Android 3.0 (API 11) SQLite 3.7.4: https://www.sqlite.org/releaselog/3_7_4.html
-- Current minimum is Android 5.0 (API 21) SQLite 3.8.6: https://www.sqlite.org/releaselog/3_8_6.html,
-- which means "The unicode61 tokenizer is now included in FTS4 by default."
CREATE VIRTUAL TABLE Search USING FTS4 (
tokenize=unicode61 'remove_diacritics=2',
name,
location
);
Expand Down
15 changes: 15 additions & 0 deletions android/database/src/main/assets/MagicHomeInventory.upgrade.6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Context: https://github.com/TWiStErRob/net.twisterrob.inventory/issues/170
-- FTS3 supported only ASCII characters, FTS4 supports unicode when used with unicode61 tokenizer.

-- Recreate the Search table with new FTS4 format.
DROP TABLE IF EXISTS Search;
CREATE VIRTUAL TABLE Search USING FTS4 (
tokenize=unicode61 'remove_diacritics=2',
name,
location
);

-- Re-insert all data into the new table.
INSERT INTO Search_Refresher (_id) SELECT _id FROM Item;
-- Compact database indexes for faster search experience.
INSERT INTO Search(Search) VALUES('optimize');
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Database(Context context) {
@VisibleForTesting
public Database(Context hostContext, Resources resources) {
super(resources);
m_helper = new DatabaseOpenHelper(hostContext, NAME, 5, BuildConfig.DEBUG) {
m_helper = new DatabaseOpenHelper(hostContext, NAME, 6, BuildConfig.DEBUG) {
@Override public void onConfigure(SQLiteDatabase db) {
super.onConfigure(db);
// CONSIDER enabling auto_vacuum=INCREMENTAL as it speeds up a large delete a lot
Expand Down

0 comments on commit bc5ddeb

Please sign in to comment.