Skip to content

Commit

Permalink
Browse & Recording: split query into words
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Oct 31, 2022
1 parent 36b503d commit 735bc2a
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/library/proxytrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QVariant>

#include "library/searchqueryparser.h"
#include "util/assert.h"

ProxyTrackModel::ProxyTrackModel(QAbstractItemModel* pTrackModel,
Expand Down Expand Up @@ -154,25 +155,41 @@ bool ProxyTrackModel::filterAcceptsRow(int sourceRow,
return false;
}

if (m_currentSearch.trimmed().isEmpty()) {
return true;
}

QStringList tokens = SearchQueryParser::splitQueryIntoWords(
m_currentSearch.trimmed());
tokens.removeDuplicates();

const QList<int>& filterColumns = m_pTrackModel->searchColumns();
QAbstractItemModel* itemModel =
dynamic_cast<QAbstractItemModel*>(m_pTrackModel);
bool rowMatches = false;

QListIterator<int> iter(filterColumns);

while (!rowMatches && iter.hasNext()) {
int i = iter.next();
QModelIndex index = itemModel->index(sourceRow, i, sourceParent);
QVariant data = itemModel->data(index);
if (data.canConvert<QString>()) {
QString strData = data.toString();
if (strData.contains(m_currentSearch, Qt::CaseInsensitive)) {
rowMatches = true;

for (QString token : tokens) {
QListIterator<int> iter(filterColumns);
bool tokenMatch = false;
while (iter.hasNext() && !tokenMatch) {
int i = iter.next();
QModelIndex index = itemModel->index(sourceRow, i, sourceParent);
QVariant data = itemModel->data(index);
if (data.canConvert<QString>()) {
QString strData = data.toString();
QString tokNoQuotes = token;
tokNoQuotes.remove('\"');
if (strData.contains(tokNoQuotes, Qt::CaseInsensitive)) {
tokenMatch = true;
tokens.removeOne(token);
}
}
}
}
return rowMatches;

if (tokens.length() > 0) {
return false;
}
return true;
}

QString ProxyTrackModel::getModelSetting(const QString& name) {
Expand Down

0 comments on commit 735bc2a

Please sign in to comment.