mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-02-09 00:08:43 +01:00
CollectionQuery: Strip off whitespaces after colon and simplify code
Fixes #1290
This commit is contained in:
parent
8ffef558ff
commit
1493164df9
@ -54,59 +54,48 @@ CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_ta
|
|||||||
// 3) Remove colons which don't correspond to column names.
|
// 3) Remove colons which don't correspond to column names.
|
||||||
|
|
||||||
// Split on whitespace
|
// Split on whitespace
|
||||||
|
QString filter_text = filter_options.filter_text().replace(QRegularExpression(":\\s+"), ":");
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||||
QStringList tokens(filter_options.filter_text().split(QRegularExpression("\\s+"), Qt::SkipEmptyParts));
|
QStringList tokens(filter_text.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts));
|
||||||
#else
|
#else
|
||||||
QStringList tokens(filter_options.filter_text().split(QRegularExpression("\\s+"), QString::SkipEmptyParts));
|
QStringList tokens(filter_text.split(QRegularExpression("\\s+"), QString::SkipEmptyParts));
|
||||||
#endif
|
#endif
|
||||||
QString query;
|
QString query;
|
||||||
for (QString token : tokens) {
|
for (QString token : tokens) {
|
||||||
token.remove('(');
|
token.remove('(')
|
||||||
token.remove(')');
|
.remove(')')
|
||||||
token.remove('"');
|
.remove('"')
|
||||||
token.replace('-', ' ');
|
.replace('-', ' ');
|
||||||
|
|
||||||
if (token.contains(':')) {
|
if (token.contains(':')) {
|
||||||
// Only prefix fts if the token is a valid column name.
|
const QString columntoken = token.section(':', 0, 0);
|
||||||
if (Song::kFtsColumns.contains("fts" + token.section(':', 0, 0), Qt::CaseInsensitive)) {
|
QString subtoken = token.section(':', 1, -1).replace(":", " ").trimmed();
|
||||||
// Account for multiple colons.
|
if (subtoken.isEmpty()) continue;
|
||||||
QString columntoken = token.section(':', 0, 0, QString::SectionIncludeTrailingSep);
|
if (Song::kFtsColumns.contains("fts" + columntoken, Qt::CaseInsensitive)) {
|
||||||
QString subtoken = token.section(':', 1, -1);
|
|
||||||
subtoken.replace(":", " ");
|
|
||||||
subtoken = subtoken.trimmed();
|
|
||||||
if (!subtoken.isEmpty()) {
|
|
||||||
if (!query.isEmpty()) query.append(" ");
|
|
||||||
query += "fts" + columntoken + "\"" + subtoken + "\"*";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Song::kNumericalColumns.contains(token.section(':', 0, 0), Qt::CaseInsensitive)) {
|
|
||||||
// Account for multiple colons.
|
|
||||||
QString columntoken = token.section(':', 0, 0);
|
|
||||||
QString subtoken = token.section(':', 1, -1);
|
|
||||||
subtoken = subtoken.trimmed();
|
|
||||||
if (!subtoken.isEmpty()) {
|
|
||||||
QString comparator = RemoveSqlOperator(subtoken);
|
|
||||||
if (columntoken.compare("rating", Qt::CaseInsensitive) == 0) {
|
|
||||||
subtoken.replace(":", " ");
|
|
||||||
AddWhereRating(subtoken, comparator);
|
|
||||||
}
|
|
||||||
else if (columntoken.compare("length", Qt::CaseInsensitive) == 0) {
|
|
||||||
// time is saved in nanoseconds, so add 9 0's
|
|
||||||
QString parsedTime = QString::number(Utilities::ParseSearchTime(subtoken)) + "000000000";
|
|
||||||
AddWhere(columntoken, parsedTime, comparator);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
subtoken.replace(":", " ");
|
|
||||||
AddWhere(columntoken, subtoken, comparator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// not a valid filter, remove
|
|
||||||
else {
|
|
||||||
token.replace(":", " ");
|
|
||||||
token = token.trimmed();
|
|
||||||
if (!query.isEmpty()) query.append(" ");
|
if (!query.isEmpty()) query.append(" ");
|
||||||
query += "\"" + token + "\"*";
|
query += "fts" + columntoken + ":\"" + subtoken + "\"*";
|
||||||
|
}
|
||||||
|
else if (Song::kNumericalColumns.contains(columntoken, Qt::CaseInsensitive)) {
|
||||||
|
QString comparator = RemoveSqlOperator(subtoken);
|
||||||
|
if (columntoken.compare("rating", Qt::CaseInsensitive) == 0) {
|
||||||
|
AddWhereRating(subtoken, comparator);
|
||||||
|
}
|
||||||
|
else if (columntoken.compare("length", Qt::CaseInsensitive) == 0) {
|
||||||
|
// Time is saved in nanoseconds, so add 9 0's
|
||||||
|
QString parsedTime = QString::number(Utilities::ParseSearchTime(subtoken)) + "000000000";
|
||||||
|
AddWhere(columntoken, parsedTime, comparator);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AddWhere(columntoken, subtoken, comparator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Not a valid filter, remove
|
||||||
|
else {
|
||||||
|
token = token.replace(":", " ").trimmed();
|
||||||
|
if (!token.isEmpty()) {
|
||||||
|
if (!query.isEmpty()) query.append(" ");
|
||||||
|
query += "\"" + token + "\"*";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -155,6 +144,7 @@ QString CollectionQuery::RemoveSqlOperator(QString &token) {
|
|||||||
if (op == "!=") {
|
if (op == "!=") {
|
||||||
op = "<>";
|
op = "<>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return op;
|
return op;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user