forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user