Skip to content

Commit

Permalink
SearchQueryParser: Try supporting spelled out OR
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Oct 5, 2023
1 parent 6858b7e commit 3e70205
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/library/searchqueryparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const QRegularExpression kSplitIntoWordsRegexp = QRegularExpression(
QStringLiteral(" " STRING_QUOTE_SUFFIX));

const QRegularExpression kSplitOnOrOperatorRegexp = QRegularExpression(
QStringLiteral("\\|" STRING_QUOTE_SUFFIX));
QStringLiteral("(?:\\||\\bOR\\b)" STRING_QUOTE_SUFFIX));

SearchQueryParser::SearchQueryParser(TrackCollection* pTrackCollection, QStringList searchColumns)
: m_pTrackCollection(pTrackCollection),
Expand Down
42 changes: 42 additions & 0 deletions src/test/searchqueryparsertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,48 @@ TEST_F(SearchQueryParserTest, EmptyOrOperator) {
EXPECT_FALSE(pQuery->match(pTrack));
}

TEST_F(SearchQueryParserTest, EmptySpelledOutOrOperator) {
auto pQuery = m_parser.parseQuery("OR", QString());

// An empty OR query matches no tracks.
TrackPointer pTrack = Track::newTemporary();
EXPECT_FALSE(pQuery->match(pTrack));
}

TEST_F(SearchQueryParserTest, LowercaseOr) {
// Lowercase 'or' is not parsed as an operator and treated literally instead
auto pQuery = m_parser.parseQuery("or", QString());

TrackPointer pTrackA = newTestTrack();
pTrackA->setTitle("or");
EXPECT_TRUE(pQuery->match(pTrackA));

TrackPointer pTrackB = newTestTrack();
pTrackB->setTitle("and");
EXPECT_FALSE(pQuery->match(pTrackB));

TrackPointer pTrackC = newTestTrack();
pTrackC->setTitle("OR");
EXPECT_TRUE(pQuery->match(pTrackC));
}

TEST_F(SearchQueryParserTest, QuotedOr) {
// Quoted uppercase 'OR' is treated literally too.
auto pQuery = m_parser.parseQuery("\"OR\"", QString());

TrackPointer pTrackA = newTestTrack();
pTrackA->setTitle("or");
EXPECT_TRUE(pQuery->match(pTrackA));

TrackPointer pTrackB = newTestTrack();
pTrackB->setTitle("and");
EXPECT_FALSE(pQuery->match(pTrackB));

TrackPointer pTrackC = newTestTrack();
pTrackC->setTitle("OR");
EXPECT_TRUE(pQuery->match(pTrackC));
}

TEST_F(SearchQueryParserTest, DurationSearchWithOrOperator) {
// Query is intentionally "misformatted" to ensure whitespace-invariance
auto pQuery = m_parser.parseQuery("duration:<39|duration:>=2:00", QString());
Expand Down

0 comments on commit 3e70205

Please sign in to comment.