|
|
@ -63,31 +63,31 @@ public class WorkerFts extends Worker {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Log.i("FTS index");
|
|
|
|
Log.i("FTS index");
|
|
|
|
|
|
|
|
Context context = getApplicationContext();
|
|
|
|
|
|
|
|
|
|
|
|
int indexed = 0;
|
|
|
|
int indexed = 0;
|
|
|
|
List<Long> ids = new ArrayList<>(INDEX_BATCH_SIZE);
|
|
|
|
List<Long> ids = new ArrayList<>(INDEX_BATCH_SIZE);
|
|
|
|
DB db = DB.getInstance(getApplicationContext());
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
SQLiteDatabase sdb = FtsDbHelper.getInstance(getApplicationContext());
|
|
|
|
SQLiteDatabase sdb = FtsDbHelper.getInstance(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
try (Cursor cursor = db.message().getMessageFts()) {
|
|
|
|
try (Cursor cursor = db.message().getMessageFts()) {
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
boolean fts = prefs.getBoolean("fts", false);
|
|
|
|
|
|
|
|
if (!fts)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long id = cursor.getLong(0);
|
|
|
|
long id = cursor.getLong(0);
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
|
|
|
if (message != null)
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Log.i("FTS index=" + message.id);
|
|
|
|
Log.i("FTS index=" + id);
|
|
|
|
|
|
|
|
|
|
|
|
File file = message.getFile(getApplicationContext());
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
|
|
|
if (message == null)
|
|
|
|
|
|
|
|
throw new FileNotFoundException("Message gone");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File file = message.getFile(context);
|
|
|
|
String text = HtmlHelper.getFullText(file);
|
|
|
|
String text = HtmlHelper.getFullText(file);
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(text))
|
|
|
|
|
|
|
|
throw new FileNotFoundException("Message empty");
|
|
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
EntityFolder folder = db.folder().getFolder(message.folder);
|
|
|
|
EntityFolder folder = db.folder().getFolder(message.folder);
|
|
|
|
if (folder != null) {
|
|
|
|
if (folder != null) {
|
|
|
|
// \\P{L}+
|
|
|
|
|
|
|
|
List<String> features = new ArrayList<>();
|
|
|
|
List<String> features = new ArrayList<>();
|
|
|
|
for (String word : text.trim().toLowerCase().split("\\W+")) {
|
|
|
|
for (String word : text.trim().toLowerCase().split("\\W+")) {
|
|
|
|
if (word.matches(".*\\d.*"))
|
|
|
|
if (word.matches(".*\\d.*"))
|
|
|
@ -108,6 +108,8 @@ public class WorkerFts extends Worker {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean fts = prefs.getBoolean("fts", false);
|
|
|
|
|
|
|
|
if (fts)
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sdb.beginTransaction();
|
|
|
|
sdb.beginTransaction();
|
|
|
|
FtsDbHelper.insert(sdb, message, text);
|
|
|
|
FtsDbHelper.insert(sdb, message, text);
|
|
|
@ -128,6 +130,7 @@ public class WorkerFts extends Worker {
|
|
|
|
Log.e(ex);
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
markIndexed(db, ids);
|
|
|
|
markIndexed(db, ids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|