Query completer: if the index is un-stripped, wait to have 2 characters before activation, to avoid excessive resource usage

This commit is contained in:
Jean-Francois Dockes 2021-11-13 12:23:42 +01:00
parent 310d28a4a1
commit 83b337fc50

View File

@ -78,8 +78,7 @@ int RclCompleterModel::rowCount(const QModelIndex &) const
QVariant RclCompleterModel::data(const QModelIndex &index, int role) const QVariant RclCompleterModel::data(const QModelIndex &index, int role) const
{ {
LOGDEB1("RclCompleterModel::data: row: " << index.row() << " role " << LOGDEB1("RclCompleterModel::data: row: " << index.row() << " role " << role << "\n");
role << "\n");
if (role != Qt::DisplayRole && role != Qt::EditRole && if (role != Qt::DisplayRole && role != Qt::EditRole &&
role != Qt::DecorationRole) { role != Qt::DecorationRole) {
return QVariant(); return QVariant();
@ -99,14 +98,12 @@ QVariant RclCompleterModel::data(const QModelIndex &index, int role) const
} }
} }
void RclCompleterModel::onPartialWord( void RclCompleterModel::onPartialWord(int tp, const QString& _qtext, const QString& qpartial)
int tp, const QString& _qtext, const QString& qpartial)
{ {
string partial = qs2u8s(qpartial); string partial = qs2u8s(qpartial);
QString qtext = _qtext.trimmed(); QString qtext = _qtext.trimmed();
bool onlyspace = qtext.isEmpty(); bool onlyspace = qtext.isEmpty();
LOGDEB1("RclCompleterModel::onPartialWord: [" << partial << "] onlyspace "<< LOGDEB1("RclCompleterModel::onPartialWord: [" << partial << "] onlyspace "<< onlyspace << "\n");
onlyspace << "\n");
currentlist.clear(); currentlist.clear();
beginResetModel(); beginResetModel();
@ -122,12 +119,10 @@ void RclCompleterModel::onPartialWord(
// Look for matches between the full entry and the search history // Look for matches between the full entry and the search history
// (anywhere in the string) // (anywhere in the string)
for (int i = 0; i < prefs.ssearchHistory.count(); i++) { for (int i = 0; i < prefs.ssearchHistory.count(); i++) {
LOGDEB1("[" << qs2u8s(prefs.ssearchHistory[i]) << "] contains [" << LOGDEB1("[" << qs2u8s(prefs.ssearchHistory[i]) << "] contains ["<<qs2u8s(qtext) << "] ?\n");
qs2u8s(qtext) << "] ?\n");
// If there is current text, only show a limited count of // If there is current text, only show a limited count of
// matching entries, else show the full history. // matching entries, else show the full history.
if (onlyspace || if (onlyspace || prefs.ssearchHistory[i].contains(qtext, Qt::CaseInsensitive)) {
prefs.ssearchHistory[i].contains(qtext, Qt::CaseInsensitive)) {
currentlist.push_back(prefs.ssearchHistory[i]); currentlist.push_back(prefs.ssearchHistory[i]);
if (!onlyspace && ++histmatch >= maxhistmatch) if (!onlyspace && ++histmatch >= maxhistmatch)
break; break;
@ -135,16 +130,17 @@ void RclCompleterModel::onPartialWord(
} }
firstfromindex = currentlist.size(); firstfromindex = currentlist.size();
// Look for Recoll terms beginning with the partial word // Look for Recoll terms beginning with the partial word. If the index is not stripped, only do
if (!qpartial.trimmed().isEmpty()) { // 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; Rcl::TermMatchResult rclmatches;
if (!rcldb->termMatch(Rcl::Db::ET_WILD, string(), if (!rcldb->termMatch(Rcl::Db::ET_WILD, string(),
partial + "*", rclmatches, maxdbtermmatch)) { partial + "*", rclmatches, maxdbtermmatch)) {
LOGDEB1("RclCompleterModel: termMatch failed: [" << partial + "*" << LOGDEB1("RclCompleterModel: termMatch failed: [" << partial + "*" << "]\n");
"]\n");
} else { } else {
LOGDEB1("RclCompleterModel: termMatch cnt: " << LOGDEB1("RclCompleterModel: termMatch cnt: " << rclmatches.entries.size() << endl);
rclmatches.entries.size() << endl);
} }
for (const auto& entry : rclmatches.entries) { for (const auto& entry : rclmatches.entries) {
LOGDEB1("RclCompleterModel: match " << entry.term << endl); LOGDEB1("RclCompleterModel: match " << entry.term << endl);