Add filetype filter in search queries
This commit is contained in:
parent
8818ba340a
commit
68d473cfb1
|
@ -128,8 +128,8 @@ const QStringList Song::kIntColumns = QStringList() << "track"
|
||||||
<< "bitrate"
|
<< "bitrate"
|
||||||
<< "samplerate";
|
<< "samplerate";
|
||||||
|
|
||||||
const QStringList Song::kFloatColumns = QStringList() << "rating" << "bpm";
|
const QStringList Song::kFloatColumns = QStringList() << "rating"
|
||||||
|
<< "bpm";
|
||||||
|
|
||||||
const QString Song::kColumnSpec = Song::kColumns.join(", ");
|
const QString Song::kColumnSpec = Song::kColumns.join(", ");
|
||||||
const QString Song::kBindSpec =
|
const QString Song::kBindSpec =
|
||||||
|
|
|
@ -29,6 +29,25 @@ const QStringList LibraryQuery::kNumericCompOperators = QStringList() << "<="
|
||||||
<< "<"
|
<< "<"
|
||||||
<< ">"
|
<< ">"
|
||||||
<< "=";
|
<< "=";
|
||||||
|
const QMap<QString, Song::FileType> kFiletypeId = QMap<QString, Song::FileType>(
|
||||||
|
std::map<QString, Song::FileType>{{"asf", Song::Type_Asf},
|
||||||
|
{"flac", Song::Type_Flac},
|
||||||
|
{"mp4", Song::Type_Mp4},
|
||||||
|
{"mpc", Song::Type_Mpc},
|
||||||
|
{"mp3", Song::Type_Mpeg},
|
||||||
|
{"oggflac", Song::Type_OggFlac},
|
||||||
|
{"oggspeex", Song::Type_OggSpeex},
|
||||||
|
{"oggvorbis", Song::Type_OggVorbis},
|
||||||
|
{"oggopus", Song::Type_OggOpus},
|
||||||
|
{"aiff", Song::Type_Aiff},
|
||||||
|
{"wav", Song::Type_Wav},
|
||||||
|
{"wavpack", Song::Type_WavPack},
|
||||||
|
{"trueaudio", Song::Type_TrueAudio},
|
||||||
|
{"cdda", Song::Type_Cdda},
|
||||||
|
{"spc700", Song::Type_Spc},
|
||||||
|
{"vgm", Song::Type_VGM},
|
||||||
|
{"stream", Song::Type_Stream},
|
||||||
|
{"unknown", Song::Type_Unknown}});
|
||||||
|
|
||||||
LibraryQuery::LibraryQuery(const QueryOptions& options)
|
LibraryQuery::LibraryQuery(const QueryOptions& options)
|
||||||
: include_unavailable_(false), join_with_fts_(false), limit_(-1) {
|
: include_unavailable_(false), join_with_fts_(false), limit_(-1) {
|
||||||
|
@ -58,14 +77,15 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
|
||||||
subtoken.replace(":", " ");
|
subtoken.replace(":", " ");
|
||||||
subtoken = subtoken.trimmed();
|
subtoken = subtoken.trimmed();
|
||||||
|
|
||||||
if (Song::kFtsColumns.contains("fts" + columntoken,
|
if (Song::kFtsColumns.contains(
|
||||||
Qt::CaseInsensitive)) { // Is it a FTS column?
|
"fts" + columntoken,
|
||||||
|
Qt::CaseInsensitive)) { // Is it a FTS column?
|
||||||
query += "fts" + columntoken + subtoken + "* ";
|
query += "fts" + columntoken + subtoken + "* ";
|
||||||
} else if (Song::kColumns.contains(columntoken, Qt::CaseInsensitive)) {
|
} else if (Song::kColumns.contains(columntoken, Qt::CaseInsensitive)) {
|
||||||
// We need to extract the operator and the value from the subtoken
|
// We need to extract the operator and the value from the subtoken
|
||||||
QRegExp operatorRe("^(" + kNumericCompOperators.join("|") + ")(.*)");
|
QRegExp operatorRe("^(" + kNumericCompOperators.join("|") + ")(.*)");
|
||||||
QString op = "="; // default if no operator given
|
QString op = "="; // default if no operator given
|
||||||
QString val = subtoken; // whole subtoken is the value if no operator
|
QString val = subtoken; // whole subtoken is the value if no operator
|
||||||
if (operatorRe.indexIn(subtoken) != -1) {
|
if (operatorRe.indexIn(subtoken) != -1) {
|
||||||
op = operatorRe.cap(1);
|
op = operatorRe.cap(1);
|
||||||
val = operatorRe.cap(2);
|
val = operatorRe.cap(2);
|
||||||
|
@ -83,10 +103,12 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
|
||||||
if (ok) {
|
if (ok) {
|
||||||
AddWhere(columntoken, doubleVal, op);
|
AddWhere(columntoken, doubleVal, op);
|
||||||
}
|
}
|
||||||
|
} else if (columntoken == "filetype") {
|
||||||
|
AddWhere(columntoken, kFiletypeId[val]);
|
||||||
} else {
|
} else {
|
||||||
AddWhere(columntoken, val, op);
|
AddWhere(columntoken, val, op);
|
||||||
}
|
}
|
||||||
} else { // We did't recognize this as a column
|
} else { // We did't recognize this as a column
|
||||||
token.replace(":", " ");
|
token.replace(":", " ");
|
||||||
token = token.trimmed();
|
token = token.trimmed();
|
||||||
query += token + "* ";
|
query += token + "* ";
|
||||||
|
@ -97,9 +119,9 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!query.isEmpty()) {
|
if (!query.isEmpty()) {
|
||||||
where_clauses_ << "fts.%fts_table_noprefix MATCH ?";
|
where_clauses_ << "fts.%fts_table_noprefix MATCH ?";
|
||||||
bound_values_ << query;
|
bound_values_ << query;
|
||||||
join_with_fts_ = true;
|
join_with_fts_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue