-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix empty filter bug #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,8 @@ void SearchQueryParser::parseTokens(QStringList tokens, | |
if (m_fuzzyMatcher.indexIn(token) != -1) { | ||
// TODO(XXX): implement this feature. | ||
} else if (m_textFilterMatcher.indexIn(token) != -1) { | ||
QString field = m_textFilterMatcher.cap(1); | ||
QString argument; | ||
QString field = m_textFilterMatcher.cap(1); | ||
QString argument; | ||
if (exact) { | ||
argument = getTextArgument( | ||
m_exactTextMatcher.cap(2), &tokens).trimmed(); | ||
|
@@ -137,11 +137,17 @@ void SearchQueryParser::parseTokens(QStringList tokens, | |
m_textFilterMatcher.cap(2), &tokens).trimmed(); | ||
} | ||
|
||
if (!argument.isEmpty()) { | ||
if (field == "crate") { | ||
if (field == "crate") { | ||
if (!argument.isEmpty()) { | ||
pNode = std::make_unique<CrateFilterNode>( | ||
&m_pTrackCollection->crates(), argument); | ||
} else if (exact) { | ||
&m_pTrackCollection->crates(), argument); | ||
} else { | ||
//TODO(gramanas) It should generate a query to | ||
//match all the tracks that are not in a crate. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An explicit |
||
} | ||
} | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put on one line: |
||
if (exact) { | ||
pNode = std::make_unique<ExactFilterNode>( | ||
m_pTrackCollection->database(), | ||
m_fieldToSqlColumns[field], argument); | ||
|
@@ -150,10 +156,8 @@ void SearchQueryParser::parseTokens(QStringList tokens, | |
m_pTrackCollection->database(), | ||
m_fieldToSqlColumns[field], argument); | ||
} | ||
} else { | ||
pNode = std::make_unique<SqlNode>( | ||
field + " IS NULL"); | ||
} | ||
|
||
} else if (m_numericFilterMatcher.indexIn(token) != -1) { | ||
QString field = m_numericFilterMatcher.cap(1); | ||
QString argument = getTextArgument( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,14 +191,21 @@ TEST_F(SearchQueryParserTest, TextFilterEmpty) { | |
searchColumns << "artist" | ||
<< "album"; | ||
|
||
// An empty argument should pass "is null" elements. | ||
// An empty argument should pass NULL and empty ("") elements. | ||
auto pQuery( | ||
m_parser.parseQuery("comment:", searchColumns, "")); | ||
m_parser.parseQuery("album: ", searchColumns, "")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add a test to check that "album: " and "album:" are treated the same. |
||
|
||
TrackPointer pTrack(Track::newTemporary()); | ||
pTrack->setComment("test ASDF test"); | ||
EXPECT_TRUE(pQuery->match(pTrack)); | ||
EXPECT_TRUE(pQuery->toSql().contains(QRegExp(".*IS NULL.*"))); | ||
pTrack->setAlbum("joe"); | ||
EXPECT_FALSE(pQuery->match(pTrack)); | ||
pTrack->setAlbum(nullptr); | ||
EXPECT_TRUE(pQuery->match(pTrack)); | ||
pTrack->setAlbum(""); | ||
EXPECT_TRUE(pQuery->match(pTrack)); | ||
|
||
EXPECT_STREQ( | ||
qPrintable(QString("(album = \"\") OR (album IS NULL)")), | ||
qPrintable(pQuery->toSql())); | ||
} | ||
|
||
TEST_F(SearchQueryParserTest, TextFilterQuote) { | ||
|
@@ -709,6 +716,7 @@ TEST_F(SearchQueryParserTest, CrateFilter) { | |
|
||
TEST_F(SearchQueryParserTest, CrateFilterEmpty) { | ||
// Empty should match everything | ||
// TODO(gramanas) Empty should match tracks without a crate. | ||
auto pQuery(m_parser.parseQuery(QString("crate: "), QStringList(), "")); | ||
|
||
TrackPointer pTrackA(Track::newTemporary()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both if statements on the 2nd level can be simplified: return
Handling the special case m_argument.isEmpty() separately seems reasonable to me.