disable full-text search engine #2

Manually merged
andreacavalli merged 1 commits from :fork into fork 2019-11-26 12:57:30 +01:00
2 changed files with 83 additions and 83 deletions
Showing only changes of commit 6ca9672aba - Show all commits

View File

@ -16,7 +16,6 @@ add_library(tdsqlite STATIC ${SQLITE_SOURCE})
target_include_directories(tdsqlite PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_include_directories(tdsqlite SYSTEM PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(tdsqlite PRIVATE ${OPENSSL_CRYPTO_LIBRARY} ${CMAKE_DL_LIBS} ${ZLIB_LIBRARIES})
target_compile_definitions(tdsqlite PRIVATE -DSQLITE_ENABLE_FTS5)
if (NOT WIN32)
target_compile_definitions(tdsqlite PRIVATE -DHAVE_USLEEP -DNDEBUG=1)

View File

@ -53,11 +53,11 @@ Status init_messages_db(SqliteDb &db, int32 version) {
}
auto add_media_indices = [&db](int begin, int end) {
for (int i = begin; i < end; i++) {
TRY_STATUS(db.exec(PSLICE() << "CREATE INDEX IF NOT EXISTS message_index_" << i
<< " ON messages (dialog_id, message_id) WHERE (index_mask & " << (1 << i)
<< ") != 0"));
}
// for (int i = begin; i < end; i++) {
// TRY_STATUS(db.exec(PSLICE() << "CREATE INDEX IF NOT EXISTS message_index_" << i
// << " ON messages (dialog_id, message_id) WHERE (index_mask & " << (1 << i)
// << ") != 0"));
// }
return Status::OK();
};
@ -66,31 +66,30 @@ Status init_messages_db(SqliteDb &db, int32 version) {
db.exec("CREATE INDEX IF NOT EXISTS message_by_search_id ON messages "
"(search_id) WHERE search_id IS NOT NULL"));
TRY_STATUS(
db.exec("CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(text, content='messages', "
"content_rowid='search_id', tokenize = \"unicode61 remove_diacritics 0 tokenchars '\a'\")"));
TRY_STATUS(db.exec(
"CREATE TRIGGER IF NOT EXISTS trigger_fts_delete BEFORE DELETE ON messages WHEN OLD.search_id IS NOT NULL"
" BEGIN INSERT INTO messages_fts(messages_fts, rowid, text) VALUES(\'delete\', OLD.search_id, OLD.text); END"));
TRY_STATUS(db.exec(
"CREATE TRIGGER IF NOT EXISTS trigger_fts_insert AFTER INSERT ON messages WHEN NEW.search_id IS NOT NULL"
" BEGIN INSERT INTO messages_fts(rowid, text) VALUES(NEW.search_id, NEW.text); END"));
//TRY_STATUS(db.exec(
//"CREATE TRIGGER IF NOT EXISTS trigger_fts_update AFTER UPDATE ON messages WHEN NEW.search_id IS NOT NULL OR "
//"OLD.search_id IS NOT NULL"
//" BEGIN "
//"INSERT INTO messages_fts(messages_fts, rowid, text) VALUES(\'delete\', OLD.search_id, OLD.text); "
//"INSERT INTO messages_fts(rowid, text) VALUES(NEW.search_id, NEW.text); "
//" END"));
// TRY_STATUS(
// db.exec("CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(text, content='messages', "
// "content_rowid='search_id', tokenize = \"unicode61 remove_diacritics 0 tokenchars '\a'\")"));
// TRY_STATUS(db.exec(
// "CREATE TRIGGER IF NOT EXISTS trigger_fts_delete BEFORE DELETE ON messages WHEN OLD.search_id IS NOT NULL"
// " BEGIN INSERT INTO messages_fts(messages_fts, rowid, text) VALUES(\'delete\', OLD.search_id, OLD.text); END"));
// TRY_STATUS(db.exec(
// "CREATE TRIGGER IF NOT EXISTS trigger_fts_insert AFTER INSERT ON messages WHEN NEW.search_id IS NOT NULL"
// " BEGIN INSERT INTO messages_fts(rowid, text) VALUES(NEW.search_id, NEW.text); END"));
// TRY_STATUS(db.exec(
// "CREATE TRIGGER IF NOT EXISTS trigger_fts_update AFTER UPDATE ON messages WHEN NEW.search_id IS NOT NULL OR "
// "OLD.search_id IS NOT NULL"
// " BEGIN "
// "INSERT INTO messages_fts(messages_fts, rowid, text) VALUES(\'delete\', OLD.search_id, OLD.text); "
// "INSERT INTO messages_fts(rowid, text) VALUES(NEW.search_id, NEW.text); "
// " END"));
return Status::OK();
};
auto add_call_index = [&db]() {
for (int i = static_cast<int>(SearchMessagesFilter::Call) - 1;
i < static_cast<int>(SearchMessagesFilter::MissedCall); i++) {
TRY_STATUS(db.exec(PSLICE() << "CREATE INDEX IF NOT EXISTS full_message_index_" << i
<< " ON messages (unique_message_id) WHERE (index_mask & " << (1 << i) << ") != 0"));
}
// for (int i = static_cast<int>(SearchMessagesFilter::Call) - 1;
// i < static_cast<int>(SearchMessagesFilter::MissedCall); i++) {
// TRY_STATUS(db.exec(PSLICE() << "CREATE INDEX IF NOT EXISTS full_message_index_" << i
// << " ON messages (unique_message_id) WHERE (index_mask & " << (1 << i) << ") != 0"));
// }
return Status::OK();
};
auto add_notification_id_index = [&db]() {
@ -197,11 +196,11 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
TRY_RESULT(get_messages_from_notification_id_stmt,
db_.get_statement("SELECT data, message_id FROM messages WHERE dialog_id = ?1 "
"AND notification_id < ?2 ORDER BY notification_id DESC LIMIT ?3"));
TRY_RESULT(
get_messages_fts_stmt,
db_.get_statement("SELECT dialog_id, data, search_id FROM messages WHERE search_id IN (SELECT rowid FROM "
"messages_fts WHERE messages_fts MATCH ?1 AND rowid < ?2 ORDER BY rowid DESC LIMIT "
"?3) ORDER BY search_id DESC"));
// TRY_RESULT(
// get_messages_fts_stmt,
// db_.get_statement("SELECT dialog_id, data, search_id FROM messages WHERE search_id IN (SELECT rowid FROM "
// "messages_fts WHERE messages_fts MATCH ?1 AND rowid < ?2 ORDER BY rowid DESC LIMIT "
// "?3) ORDER BY search_id DESC"));
for (int32 i = 0; i < MESSAGES_DB_INDEX_COUNT; i++) {
TRY_RESULT(get_messages_from_index_desc_stmt,
@ -245,7 +244,7 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
get_messages_stmt_.desc_stmt_ = std::move(get_messages_desc_stmt);
get_messages_from_notification_id_stmt_ = std::move(get_messages_from_notification_id_stmt);
get_messages_fts_stmt_ = std::move(get_messages_fts_stmt);
// get_messages_fts_stmt_ = std::move(get_messages_fts_stmt);
// LOG(ERROR) << get_message_stmt_.explain().ok();
// LOG(ERROR) << get_messages_from_notification_id_stmt.explain().ok();
@ -605,56 +604,58 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
}
Result<MessagesDbFtsResult> get_messages_fts(MessagesDbFtsQuery query) override {
SCOPE_EXIT {
get_messages_fts_stmt_.reset();
};
// SCOPE_EXIT {
// get_messages_fts_stmt_.reset();
// };
LOG(INFO) << tag("query", query.query) << query.dialog_id << tag("index_mask", query.index_mask)
<< tag("from_search_id", query.from_search_id) << tag("limit", query.limit);
string words = prepare_query(query.query);
LOG(INFO) << tag("from", query.query) << tag("to", words);
// LOG(INFO) << tag("query", query.query) << query.dialog_id << tag("index_mask", query.index_mask)
// << tag("from_search_id", query.from_search_id) << tag("limit", query.limit);
// string words = prepare_query(query.query);
// LOG(INFO) << tag("from", query.query) << tag("to", words);
//
// dialog_id kludge
// if (query.dialog_id.is_valid()) {
// words += PSTRING() << " \"\a" << query.dialog_id.get() << "\"";
// }
//
// index_mask kludge
// if (query.index_mask != 0) {
// int index_i = -1;
// for (int i = 0; i < MESSAGES_DB_INDEX_COUNT; i++) {
// if (query.index_mask == (1 << i)) {
// index_i = i;
// break;
// }
// }
// if (index_i == -1) {
// return Status::Error("Union of index types is not supported");
// }
// words += PSTRING() << " \"\a\a" << index_i << "\"";
// }
//
// auto &stmt = get_messages_fts_stmt_;
// stmt.bind_string(1, words).ensure();
// if (query.from_search_id == 0) {
// query.from_search_id = std::numeric_limits<int64>::max();
// }
// stmt.bind_int64(2, query.from_search_id).ensure();
// stmt.bind_int32(3, query.limit).ensure();
// MessagesDbFtsResult result;
// auto status = stmt.step();
// if (status.is_error()) {
// LOG(ERROR) << status;
// return std::move(result);
// }
// while (stmt.has_row()) {
// auto dialog_id = stmt.view_int64(0);
// auto data_slice = stmt.view_blob(1);
// auto search_id = stmt.view_int64(2);
// result.next_search_id = search_id;
// result.messages.push_back(MessagesDbMessage{DialogId(dialog_id), BufferSlice(data_slice)});
// stmt.step().ensure();
// }
// dialog_id kludge
if (query.dialog_id.is_valid()) {
words += PSTRING() << " \"\a" << query.dialog_id.get() << "\"";
}
// index_mask kludge
if (query.index_mask != 0) {
int index_i = -1;
for (int i = 0; i < MESSAGES_DB_INDEX_COUNT; i++) {
if (query.index_mask == (1 << i)) {
index_i = i;
break;
}
}
if (index_i == -1) {
return Status::Error("Union of index types is not supported");
}
words += PSTRING() << " \"\a\a" << index_i << "\"";
}
auto &stmt = get_messages_fts_stmt_;
stmt.bind_string(1, words).ensure();
if (query.from_search_id == 0) {
query.from_search_id = std::numeric_limits<int64>::max();
}
stmt.bind_int64(2, query.from_search_id).ensure();
stmt.bind_int32(3, query.limit).ensure();
MessagesDbFtsResult result;
auto status = stmt.step();
if (status.is_error()) {
LOG(ERROR) << status;
return std::move(result);
}
while (stmt.has_row()) {
auto dialog_id = stmt.view_int64(0);
auto data_slice = stmt.view_blob(1);
auto search_id = stmt.view_int64(2);
result.next_search_id = search_id;
result.messages.push_back(MessagesDbMessage{DialogId(dialog_id), BufferSlice(data_slice)});
stmt.step().ensure();
}
return std::move(result);
}
@ -750,7 +751,7 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
std::array<GetMessagesStmt, MESSAGES_DB_INDEX_COUNT> get_messages_from_index_stmts_;
std::array<SqliteStatement, 2> get_calls_stmts_;
SqliteStatement get_messages_fts_stmt_;
// SqliteStatement get_messages_fts_stmt_;
Result<std::vector<BufferSlice>> get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id,
MessageId from_message_id, int32 offset, int32 limit) {