Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: also search for half & double BPM #12070

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/library/searchqueryparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,36 @@ void SearchQueryParser::parseTokens(QStringList tokens,
.trimmed();

if (!argument.isEmpty()) {
bool isSingleNumber = false;
double bpm = argument.toDouble(&isSingleNumber);
if (argument == kMissingFieldSearchTerm) {
pNode = std::make_unique<NullNumericFilterNode>(
m_fieldToSqlColumns[field]);
} else if (field == "bpm" && isSingleNumber) {
// If it's a single number also search for half & double BPM
// Add literal BPM value
auto gNode = std::make_unique<OrNode>();
gNode->addNode(std::make_unique<NumericFilterNode>(
m_fieldToSqlColumns[field], argument));
// Add half BPM
// If the halve is not an integer, use range prev-next integer
QString halfStr = QString::number(bpm / 2);
bool halveIsInt = false;
int half = halfStr.toInt(&halveIsInt);
if (halveIsInt) {
gNode->addNode(std::make_unique<NumericFilterNode>(
m_fieldToSqlColumns[field], QString::number(half)));
} else {
gNode->addNode(std::make_unique<NumericFilterNode>(
m_fieldToSqlColumns[field],
QStringLiteral("%1-%2").arg(
QString::number(floor(bpm / 2)),
QString::number(ceil(bpm / 2)))));
}
// Add double BPM
gNode->addNode(std::make_unique<NumericFilterNode>(
m_fieldToSqlColumns[field], QString::number(bpm * 2)));
pNode = std::move(gNode);
} else {
pNode = std::make_unique<NumericFilterNode>(
m_fieldToSqlColumns[field], argument);
Expand Down
Loading