mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-29 18:08:02 +03:00
fix(#77): Make docset filter case-insensitive
This commit is contained in:
parent
bde4990148
commit
ccf5568a21
@ -59,14 +59,14 @@ void ZealDocsetsRegistry::_runQuery(const QString& rawQuery, int queryNum)
|
||||
if(queryNum != lastQuery) return; // some other queries pending - ignore this one
|
||||
|
||||
QList<ZealSearchResult> results;
|
||||
|
||||
ZealSearchQuery query = ZealSearchQuery(rawQuery);
|
||||
ZealSearchQuery query(rawQuery);
|
||||
|
||||
QString docsetPrefix = query.getDocsetFilter();
|
||||
QString preparedQuery = query.getSanitizedQuery();
|
||||
bool hasPrefixFilter = !docsetPrefix.isEmpty();
|
||||
|
||||
for(QString name : names()) {
|
||||
if(!docsetPrefix.isEmpty() && !name.toLower().contains(docsetPrefix)) {
|
||||
for (const QString &name : names()) {
|
||||
if (hasPrefixFilter && !name.contains(docsetPrefix, Qt::CaseInsensitive)) {
|
||||
// Filter out this docset as the names don't match the docset prefix
|
||||
continue;
|
||||
}
|
||||
|
@ -1,6 +1,33 @@
|
||||
#include "zealsearchresult.h"
|
||||
|
||||
ZealSearchResult::ZealSearchResult(const QString& name_, const QString& parentName_, const QString& path_, const QString& docset_, const QString& query_)
|
||||
: name(name_), parentName(parentName_), path(path_), docset(docset_), query(query_)
|
||||
ZealSearchResult::ZealSearchResult()
|
||||
{}
|
||||
|
||||
ZealSearchResult::ZealSearchResult(const QString &name_,
|
||||
const QString &parentName_,
|
||||
const QString &path_,
|
||||
const QString &docset_,
|
||||
const QString &query_)
|
||||
: name(name_)
|
||||
, parentName(parentName_)
|
||||
, path(path_)
|
||||
, docset(docset_)
|
||||
, query(query_)
|
||||
{}
|
||||
|
||||
bool ZealSearchResult::operator<(const ZealSearchResult &r) const
|
||||
{
|
||||
const bool lhsStartsWithQuery = name.startsWith(query, Qt::CaseInsensitive);
|
||||
const bool rhsStartsWithQuery = r.name.startsWith(query, Qt::CaseInsensitive);
|
||||
|
||||
if (lhsStartsWithQuery != rhsStartsWithQuery) {
|
||||
return lhsStartsWithQuery > rhsStartsWithQuery;
|
||||
}
|
||||
|
||||
const int namesCmp = QString::compare(name, r.name, Qt::CaseInsensitive);
|
||||
if (namesCmp) {
|
||||
return namesCmp < 0;
|
||||
}
|
||||
|
||||
return QString::compare(name, r.name, Qt::CaseInsensitive) < 0;
|
||||
}
|
||||
|
@ -6,23 +6,25 @@
|
||||
class ZealSearchResult
|
||||
{
|
||||
public:
|
||||
ZealSearchResult(const QString& name_, const QString& parentName_, const QString& path_, const QString& docset_, const QString& query_);
|
||||
const QString& getName() const { return name; };
|
||||
const QString& getParentName() const { return parentName; };
|
||||
const QString& getPath() const { return path; };
|
||||
const QString& getDocsetName() const { return docset; };
|
||||
bool operator<(const ZealSearchResult& r) const {
|
||||
if (name.toLower().startsWith(query.toLower()) > r.name.toLower().startsWith(r.query.toLower())) {
|
||||
// return results that are prefixed with query first
|
||||
return true;
|
||||
} else if (name.toLower().startsWith(query.toLower()) < r.name.toLower().startsWith(r.query.toLower())) {
|
||||
return false;
|
||||
} else {
|
||||
return name.toLower() < r.name.toLower() ||
|
||||
(name.toLower() == r.name.toLower()
|
||||
&& parentName.toLower() < r.parentName.toLower());
|
||||
}
|
||||
}
|
||||
|
||||
ZealSearchResult();
|
||||
|
||||
ZealSearchResult(const QString &name_,
|
||||
const QString &parentName_,
|
||||
const QString &path_,
|
||||
const QString &docset_,
|
||||
const QString &query_);
|
||||
|
||||
QString getName() const { return name; }
|
||||
|
||||
QString getParentName() const { return parentName; }
|
||||
|
||||
QString getPath() const { return path; }
|
||||
|
||||
QString getDocsetName() const { return docset; }
|
||||
|
||||
bool operator<(const ZealSearchResult& r) const;
|
||||
|
||||
private:
|
||||
QString name;
|
||||
QString parentName;
|
||||
|
Loading…
Reference in New Issue
Block a user