LIMIT global search

This commit is contained in:
B. Petersen
2021-04-20 12:34:44 +02:00
committed by bjoern
parent 99373774aa
commit 3f1623eab1
2 changed files with 12 additions and 1 deletions

View File

@@ -1272,6 +1272,12 @@ uint32_t dc_get_chat_ephemeral_timer (dc_context_t* context, uint32_t chat_id);
* search results may just hilite the corresponding messages and present a
* prev/next button.
*
* For global search, result is limited to 1000 messages,
* this allows incremental search done fast.
* So, when getting exactly 1000 results, the result may be truncated;
* the UIs may display sth. as "1000+ messages found" in this case.
* Chat search (if a chat_id is set) is not limited.
*
* @memberof dc_context_t
* @param context The context object as returned from dc_context_new().
* @param chat_id ID of the chat to search messages in.

View File

@@ -503,6 +503,11 @@ impl Context {
//
// Unlike chat view, sorting by `timestamp` is not necessary but slows down the query by
// ~25% according to benchmarks.
//
// To speed up incremental search, where queries for few characters usually return lots
// of unwanted results that are discarded moments later, we added `LIMIT 1000`.
// According to some tests, this limit speeds up eg. 2 character searches by factor 10.
// The limit is documented and UI may add a hint when getting 1000 results.
self.sql
.fetch(
sqlx::query(
@@ -517,7 +522,7 @@ impl Context {
AND c.blocked=0
AND ct.blocked=0
AND m.txt LIKE ?
ORDER BY m.id DESC",
ORDER BY m.id DESC LIMIT 1000",
)
.bind(str_like_in_text),
)