()
| 50 | } |
| 51 | |
| 52 | @NonNull |
| 53 | @Override |
| 54 | public Result doWork() { |
| 55 | Thread.currentThread().setPriority(THREAD_PRIORITY_BACKGROUND); |
| 56 | |
| 57 | try { |
| 58 | Log.i("FTS index"); |
| 59 | Context context = getApplicationContext(); |
| 60 | |
| 61 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 62 | boolean checkpoints = prefs.getBoolean("sqlite_checkpoints", true); |
| 63 | |
| 64 | int indexed = 0; |
| 65 | List<Long> ids = new ArrayList<>(INDEX_BATCH_SIZE); |
| 66 | DB db = DB.getInstance(context); |
| 67 | |
| 68 | SQLiteDatabase sdb = Fts4DbHelper.getInstance(context); |
| 69 | |
| 70 | try (Cursor cursor = db.message().getMessageFts()) { |
| 71 | while (cursor != null && cursor.moveToNext()) |
| 72 | try { |
| 73 | long id = cursor.getLong(0); |
| 74 | Log.i("FTS index=" + id); |
| 75 | |
| 76 | ids.add(id); |
| 77 | |
| 78 | EntityMessage message = db.message().getMessage(id); |
| 79 | if (message == null) { |
| 80 | Log.i("FTS gone"); |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | List<EntityAttachment> attachments = db.attachment().getAttachments(message.id); |
| 85 | |
| 86 | String text = null; |
| 87 | if (message.content) { |
| 88 | File file = message.getFile(context); |
| 89 | text = HtmlHelper.getFullText(context, file); |
| 90 | } |
| 91 | |
| 92 | try { |
| 93 | sdb.beginTransaction(); |
| 94 | Fts4DbHelper.insert(sdb, message, attachments, text); |
| 95 | sdb.setTransactionSuccessful(); |
| 96 | } catch (SQLiteException ex) { |
| 97 | Log.w(ex); |
| 98 | break; |
| 99 | } finally { |
| 100 | sdb.endTransaction(); |
| 101 | } |
| 102 | |
| 103 | indexed++; |
| 104 | |
| 105 | if (ids.size() >= INDEX_BATCH_SIZE) |
| 106 | markIndexed(db, ids); |
| 107 | |
| 108 | boolean fts = prefs.getBoolean("fts", false); |
| 109 | if (!fts) |
nothing calls this directly
no test coverage detected