summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2012-06-01 14:44:44 +0200
committerKarsten Heimrich <karsten.heimrich@nokia.com>2012-06-04 12:15:46 +0200
commita031d5f6862739a1e4d2ebc4002615321f75c92b (patch)
tree845b23a8c7a6e6bbf7bd24829d18060b06a3649f /src/plugins/coreplugin
parent671bfb92500b6bd16f753f4b4dd405513129920f (diff)
downloadqt-creator-a031d5f6862739a1e4d2ebc4002615321f75c92b.tar.gz
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: Niels Weber <niels.2.weber@nokia.com> Reviewed-by: Karsten Heimrich <karsten.heimrich@nokia.com>
Diffstat (limited to 'src/plugins/coreplugin')
-rw-r--r--src/plugins/coreplugin/helpmanager.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/plugins/coreplugin/helpmanager.cpp b/src/plugins/coreplugin/helpmanager.cpp
index 3852e1a113..df9f6b8655 100644
--- a/src/plugins/coreplugin/helpmanager.cpp
+++ b/src/plugins/coreplugin/helpmanager.cpp
@@ -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 (db.open()) {
QSqlQuery query = QSqlQuery(db);
query.setForwardOnly(true);
- 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 (query.next()) {
const QString &keyValue = query.value(0).toString();
if (!keyValue.isEmpty()) {
- keywords.append(keyValue);
- if (keywords.count() == maxHits)
- return keywords;
+ if (keyValue.startsWith(key, Qt::CaseInsensitive))
+ keywordsToSort.insert(keyValue);
+ else
+ keywords.insert(keyValue);
}
}
}
}
}
- return keywords;
+
+ QStringList keywordsSorted = keywordsToSort.toList();
+ qSort(keywordsSorted.begin(), keywordsSorted.end());
+ return keywordsSorted + keywords.toList();
}
QUrl HelpManager::findFile(const QUrl &url) const