Commit a031d5f6 authored by kh1's avatar kh1 Committed by Karsten Heimrich
Browse files

Sort the search hits to match the actual search term.

The former unsorted list would not fully match the search term,
while searching for QString the actual top hit would be somewhere
in between other search results instead of position one. Make sure
to remove duplicates from the search hits.

Task-number: QTCREATORBUG-5167

Change-Id: I640c3e8d5a5498c5a13c083370a961f458576da5
Reviewed-by: default avatarNiels Weber <>
Reviewed-by: default avatarKarsten Heimrich <>
parent 671bfb92
......@@ -225,13 +225,15 @@ QMap<QString, QUrl> HelpManager::linksForIdentifier(const QString &id) const
// This should go into Qt 4.8 once we start using it for Qt Creator
QStringList HelpManager::findKeywords(const QString &key, int maxHits) const
QStringList keywords;
if (d->m_needsSetup)
return keywords;
return QStringList();
const QLatin1String sqlite("QSQLITE");
const QLatin1String name("HelpManager::findKeywords");
QSet<QString> keywords;
QSet<QString> keywordsToSort;
DbCleaner cleaner(name);
QSqlDatabase db = QSqlDatabase::addDatabase(sqlite, name);
if (db.driver() && db.driver()->lastError().type() == QSqlError::NoError) {
......@@ -245,20 +247,24 @@ QStringList HelpManager::findKeywords(const QString &key, int maxHits) const
if ( {
QSqlQuery query = QSqlQuery(db);
query.exec(QString::fromLatin1("SELECT DISTINCT Name FROM "
"IndexTable WHERE Name LIKE '%%1%'").arg(key));
query.exec(QString::fromLatin1("SELECT DISTINCT Name FROM IndexTable WHERE Name LIKE "
"'%%1%' LIMIT %2").arg(key, QString::number(maxHits)));
while ( {
const QString &keyValue = query.value(0).toString();
if (!keyValue.isEmpty()) {
if (keywords.count() == maxHits)
return keywords;
if (keyValue.startsWith(key, Qt::CaseInsensitive))
return keywords;
QStringList keywordsSorted = keywordsToSort.toList();
qSort(keywordsSorted.begin(), keywordsSorted.end());
return keywordsSorted + keywords.toList();
QUrl HelpManager::findFile(const QUrl &url) const
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment