Skip to content

Commit 9f40252

Browse files
committed
artist: now shows only songs with empty artist values
1 parent befecfc commit 9f40252

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/library/features/mixxxlibrary/mixxxlibrarytreemodel.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ QVariant MixxxLibraryTreeModel::getQuery(TreeItem* pTree) const {
174174
return "$groupingSettings$";
175175
}
176176

177-
const QString param("%1:=%2");
177+
const QString param("%1:=\"%2\"");
178178

179179
int depth = 0;
180180
TreeItem* pAux = pTree;
@@ -193,12 +193,6 @@ QVariant MixxxLibraryTreeModel::getQuery(TreeItem* pTree) const {
193193
if (pAux->isDivider()) {
194194
value.append("*");
195195
}
196-
if (value == "") {
197-
value = "0";
198-
}
199-
if (value != "0") {
200-
value = "\"" + value + "\"";
201-
}
202196
result << param.arg(m_sortOrder[depth], value);
203197

204198
pAux = pAux->parent();

src/library/searchqueryparser.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ SearchQueryParser::SearchQueryParser(TrackCollection* pTrackCollection)
6161
m_fuzzyMatcher = QRegExp(QString("^~(%1)$").arg(m_allFilters.join("|")));
6262
m_textFilterMatcher = QRegExp(QString("^-?(%1):(.*)$").arg(m_textFilters.join("|")));
6363
m_exactTextMatcher = QRegExp(QString("^-?(%1):=(.*)$").arg(m_textFilters.join("|")));
64-
m_nullFilterMatcher = QRegExp(QString("^-?(%1):=0$").arg(m_textFilters.join("|")));
6564
m_numericFilterMatcher = QRegExp(QString("^-?(%1):(.*)$").arg(m_numericFilters.join("|")));
6665
m_specialFilterMatcher = QRegExp(QString("^[~-]?(%1):(.*)$").arg(m_specialFilters.join("|")));
6766
}
@@ -122,7 +121,6 @@ void SearchQueryParser::parseTokens(QStringList tokens,
122121
}
123122

124123
bool exact = m_exactTextMatcher.indexIn(token) != -1;
125-
bool nullMatch = m_nullFilterMatcher.indexIn(token) != -1;
126124
bool negate = token.startsWith(kNegatePrefix);
127125
std::unique_ptr<QueryNode> pNode;
128126

@@ -139,24 +137,28 @@ void SearchQueryParser::parseTokens(QStringList tokens,
139137
m_textFilterMatcher.cap(2), &tokens).trimmed();
140138
}
141139

142-
if (!argument.isEmpty()) {
143-
if (field == "crate") {
140+
if (field == "crate") {
141+
if (!argument.isEmpty()) {
144142
pNode = std::make_unique<CrateFilterNode>(
145-
&m_pTrackCollection->crates(), argument);
146-
} else if (exact) {
147-
if (nullMatch) {
148-
pNode = std::make_unique<SqlNode>(QString(
149-
"(%1 LIKE \"\") OR (%1 IS NULL)").arg(field));
150-
} else {
151-
pNode = std::make_unique<ExactFilterNode>(
152-
m_pTrackCollection->database(),
153-
m_fieldToSqlColumns[field], argument);
154-
}
143+
&m_pTrackCollection->crates(), argument);
144+
} else {
145+
//TODO(gramanas) It should generate a query to
146+
//match all the tracks that are not in a crate.
147+
}
148+
}
149+
else if (!argument.isEmpty()) {
150+
if (exact) {
151+
pNode = std::make_unique<ExactFilterNode>(
152+
m_pTrackCollection->database(),
153+
m_fieldToSqlColumns[field], argument);
155154
} else {
156155
pNode = std::make_unique<TextFilterNode>(
157156
m_pTrackCollection->database(),
158157
m_fieldToSqlColumns[field], argument);
159158
}
159+
} else {
160+
pNode = std::make_unique<SqlNode>(QString(
161+
"(%1 = \"\") OR (%1 IS NULL)").arg(field));
160162
}
161163

162164
} else if (m_numericFilterMatcher.indexIn(token) != -1) {

src/library/searchqueryparser.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class SearchQueryParser {
3939

4040
QRegExp m_fuzzyMatcher;
4141
QRegExp m_textFilterMatcher;
42-
QRegExp m_nullFilterMatcher;
4342
QRegExp m_exactTextMatcher;
4443
QRegExp m_numericFilterMatcher;
4544
QRegExp m_specialFilterMatcher;

src/test/searchqueryparsertest.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,20 @@ TEST_F(SearchQueryParserTest, TextFilterEmpty) {
191191
searchColumns << "artist"
192192
<< "album";
193193

194-
// An empty argument should pass "is null" elements.
194+
// An empty argument should pass NULL and empty ("") elements.
195195
auto pQuery(
196-
m_parser.parseQuery("comment:", searchColumns, ""));
196+
m_parser.parseQuery("artist:", searchColumns, ""));
197197

198198
TrackPointer pTrack(Track::newTemporary());
199-
pTrack->setComment("test ASDF test");
199+
pTrack->setArtist("joe");
200+
EXPECT_FALSE(pQuery->match(pTrack));
201+
pTrack->setArtist(nullptr);
202+
EXPECT_TRUE(pQuery->match(pTrack));
203+
pTrack->setArtist("");
200204
EXPECT_TRUE(pQuery->match(pTrack));
201205

202206
EXPECT_STREQ(
203-
qPrintable(QString("")),
207+
qPrintable(QString("(artist = \"\") OR (artist IS NULL)")),
204208
qPrintable(pQuery->toSql()));
205209
}
206210

@@ -712,6 +716,7 @@ TEST_F(SearchQueryParserTest, CrateFilter) {
712716

713717
TEST_F(SearchQueryParserTest, CrateFilterEmpty) {
714718
// Empty should match everything
719+
// TODO(gramanas) Empty should match tracks without a crate.
715720
auto pQuery(m_parser.parseQuery(QString("crate: "), QStringList(), ""));
716721

717722
TrackPointer pTrackA(Track::newTemporary());

0 commit comments

Comments
 (0)