From 83b337fc50faed05580ba94aa1f83c18b264fe94 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 13 Nov 2021 12:23:42 +0100 Subject: [PATCH] Query completer: if the index is un-stripped, wait to have 2 characters before activation, to avoid excessive resource usage --- src/qtgui/ssearch_w.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index 8f5be51d..ba3e99d6 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -78,8 +78,7 @@ int RclCompleterModel::rowCount(const QModelIndex &) const QVariant RclCompleterModel::data(const QModelIndex &index, int role) const { - LOGDEB1("RclCompleterModel::data: row: " << index.row() << " role " << - role << "\n"); + LOGDEB1("RclCompleterModel::data: row: " << index.row() << " role " << role << "\n"); if (role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::DecorationRole) { return QVariant(); @@ -99,14 +98,12 @@ QVariant RclCompleterModel::data(const QModelIndex &index, int role) const } } -void RclCompleterModel::onPartialWord( - int tp, const QString& _qtext, const QString& qpartial) +void RclCompleterModel::onPartialWord(int tp, const QString& _qtext, const QString& qpartial) { string partial = qs2u8s(qpartial); QString qtext = _qtext.trimmed(); bool onlyspace = qtext.isEmpty(); - LOGDEB1("RclCompleterModel::onPartialWord: [" << partial << "] onlyspace "<< - onlyspace << "\n"); + LOGDEB1("RclCompleterModel::onPartialWord: [" << partial << "] onlyspace "<< onlyspace << "\n"); currentlist.clear(); beginResetModel(); @@ -122,12 +119,10 @@ void RclCompleterModel::onPartialWord( // Look for matches between the full entry and the search history // (anywhere in the string) for (int i = 0; i < prefs.ssearchHistory.count(); i++) { - LOGDEB1("[" << qs2u8s(prefs.ssearchHistory[i]) << "] contains [" << - qs2u8s(qtext) << "] ?\n"); + LOGDEB1("[" << qs2u8s(prefs.ssearchHistory[i]) << "] contains ["<= maxhistmatch) break; @@ -135,16 +130,17 @@ void RclCompleterModel::onPartialWord( } firstfromindex = currentlist.size(); - // Look for Recoll terms beginning with the partial word - if (!qpartial.trimmed().isEmpty()) { + // Look for Recoll terms beginning with the partial word. If the index is not stripped, only do + // this after the partial has at least 2 characters, else the syn/diac/case expansion is too + // expensive + int mintermsizeforexpand = o_index_stripchars ? 1 : 2; + if (qpartial.trimmed().size() >= mintermsizeforexpand) { Rcl::TermMatchResult rclmatches; if (!rcldb->termMatch(Rcl::Db::ET_WILD, string(), partial + "*", rclmatches, maxdbtermmatch)) { - LOGDEB1("RclCompleterModel: termMatch failed: [" << partial + "*" << - "]\n"); + LOGDEB1("RclCompleterModel: termMatch failed: [" << partial + "*" << "]\n"); } else { - LOGDEB1("RclCompleterModel: termMatch cnt: " << - rclmatches.entries.size() << endl); + LOGDEB1("RclCompleterModel: termMatch cnt: " << rclmatches.entries.size() << endl); } for (const auto& entry : rclmatches.entries) { LOGDEB1("RclCompleterModel: match " << entry.term << endl);