Don't show a last.fm result if any token didn't match
This commit is contained in:
parent
a6f4a76618
commit
0a5ef8382d
@ -29,6 +29,8 @@ LastFMSearchProvider::LastFMSearchProvider(LastFMService* service, QObject* pare
|
|||||||
Init("Last.fm", "lastfm", QIcon(":last.fm/as.png"), false, true);
|
Init("Last.fm", "lastfm", QIcon(":last.fm/as.png"), false, true);
|
||||||
icon_ = ScaleAndPad(QImage(":last.fm/as.png"));
|
icon_ = ScaleAndPad(QImage(":last.fm/as.png"));
|
||||||
|
|
||||||
|
safe_words_ << "lastfm" << "last.fm";
|
||||||
|
|
||||||
connect(service, SIGNAL(SavedItemsChanged()), SLOT(RecreateItems()));
|
connect(service, SIGNAL(SavedItemsChanged()), SLOT(RecreateItems()));
|
||||||
RecreateItems();
|
RecreateItems();
|
||||||
}
|
}
|
||||||
@ -46,19 +48,33 @@ SearchProvider::ResultList LastFMSearchProvider::Search(int id, const QString& q
|
|||||||
foreach (const QString& token, tokens) {
|
foreach (const QString& token, tokens) {
|
||||||
if (item.keyword_.startsWith(token, Qt::CaseInsensitive)) {
|
if (item.keyword_.startsWith(token, Qt::CaseInsensitive)) {
|
||||||
result.match_quality_ = Result::Quality_AtStart;
|
result.match_quality_ = Result::Quality_AtStart;
|
||||||
result.metadata_ = item.metadata_;
|
continue;
|
||||||
break; // Next item
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result::MatchQuality quality = MatchQuality(tokens, item.metadata_.title());
|
int index = item.metadata_.title().indexOf(token, 0, Qt::CaseInsensitive);
|
||||||
if (quality == Result::Quality_None)
|
if (index == -1) {
|
||||||
continue;
|
bool matched_safe_word = false;
|
||||||
|
foreach (const QString& safe_word, safe_words_) {
|
||||||
|
if (safe_word.startsWith(token, Qt::CaseInsensitive)) {
|
||||||
|
matched_safe_word = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result.match_quality_ = qMin(quality, result.match_quality_);
|
if (matched_safe_word)
|
||||||
result.metadata_ = item.metadata_;
|
continue;
|
||||||
|
result.match_quality_ = Result::Quality_None;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.match_quality_ = qMin(result.match_quality_, Result::Quality_Middle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.match_quality_ == Result::Quality_Middle) {
|
||||||
|
result.match_quality_ = MatchQuality(tokens, result.metadata_.title());
|
||||||
|
}
|
||||||
if (result.match_quality_ != Result::Quality_None) {
|
if (result.match_quality_ != Result::Quality_None) {
|
||||||
|
result.metadata_ = item.metadata_;
|
||||||
ret << result;
|
ret << result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
LastFMService* service_;
|
LastFMService* service_;
|
||||||
|
|
||||||
|
QStringList safe_words_;
|
||||||
|
|
||||||
QImage icon_;
|
QImage icon_;
|
||||||
|
|
||||||
struct Item {
|
struct Item {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user