diff --git a/src/filterparser/filterparser.cpp b/src/filterparser/filterparser.cpp index 3c2a5ba30..01112e0e9 100644 --- a/src/filterparser/filterparser.cpp +++ b/src/filterparser/filterparser.cpp @@ -246,7 +246,7 @@ FilterTree *FilterParser::createSearchTermTreeNode(const QString &column, const cmp = new FilterParserTextNeComparator(value); } else { - cmp = new FilterParserDefaultComparator(value); + cmp = new FilterParserTextContainsComparator(value); } } else if (Song::kIntSearchColumns.contains(column, Qt::CaseInsensitive)) { @@ -363,7 +363,7 @@ FilterTree *FilterParser::createSearchTermTreeNode(const QString &column, const return new FilterColumnTerm(column, cmp); } - return new FilterTerm(Song::kTextSearchColumns, new FilterParserDefaultComparator(value)); + return new FilterTerm(new FilterParserTextContainsComparator(value)); } diff --git a/src/filterparser/filterparsersearchcomparators.h b/src/filterparser/filterparsersearchcomparators.h index 15ecd90d8..3f09f1d2e 100644 --- a/src/filterparser/filterparsersearchcomparators.h +++ b/src/filterparser/filterparsersearchcomparators.h @@ -38,16 +38,16 @@ class FilterParserSearchTermComparator { }; // "compares" by checking if the field contains the search term -class FilterParserDefaultComparator : public FilterParserSearchTermComparator { +class FilterParserTextContainsComparator : public FilterParserSearchTermComparator { public: - explicit FilterParserDefaultComparator(const QString &search_term) : search_term_(search_term) {} + explicit FilterParserTextContainsComparator(const QString &search_term) : search_term_(search_term) {} bool Matches(const QVariant &value) const override { - return value.toString().contains(search_term_, Qt::CaseInsensitive); + return value.metaType().id() == QMetaType::QString && value.toString().contains(search_term_, Qt::CaseInsensitive); } private: QString search_term_; - Q_DISABLE_COPY(FilterParserDefaultComparator) + Q_DISABLE_COPY(FilterParserTextContainsComparator) }; class FilterParserTextEqComparator : public FilterParserSearchTermComparator { diff --git a/src/filterparser/filtertree.h b/src/filterparser/filtertree.h index 52d52e327..7098f1ca2 100644 --- a/src/filterparser/filtertree.h +++ b/src/filterparser/filtertree.h @@ -67,19 +67,27 @@ class NopFilter : public FilterTree { // Filter that applies a SearchTermComparator to all fields class FilterTerm : public FilterTree { public: - explicit FilterTerm(const QStringList &columns, FilterParserSearchTermComparator *comparator) : columns_(columns), cmp_(comparator) {} + explicit FilterTerm(FilterParserSearchTermComparator *comparator) : cmp_(comparator) {} FilterType type() const override { return FilterType::Term; } bool accept(const Song &song) const override { - for (const QString &column : columns_) { - if (cmp_->Matches(DataFromColumn(column, song))) return true; - } + + if (cmp_->Matches(song.PrettyTitle())) return true; + if (cmp_->Matches(song.album())) return true; + if (cmp_->Matches(song.artist())) return true; + if (cmp_->Matches(song.albumartist())) return true; + if (cmp_->Matches(song.composer())) return true; + if (cmp_->Matches(song.performer())) return true; + if (cmp_->Matches(song.grouping())) return true; + if (cmp_->Matches(song.genre())) return true; + if (cmp_->Matches(song.comment())) return true; + return false; + } private: - const QStringList columns_; QScopedPointer cmp_; };