Skip to content

Commit

Permalink
TextFilterNode: Add StartsWith and EndsWith to StringMatch
Browse files Browse the repository at this point in the history
There is no method for parsing these operators from a search query yet.
At this stage, they are present purely for supporting all fields and
operators already present in mixxxdj#14182.
  • Loading branch information
cr7pt0gr4ph7 committed Feb 15, 2025
1 parent ea756e9 commit 94e6953
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/library/searchquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ bool TextFilterNode::match(const TrackPointer& pTrack) const {
if (strValue == m_argument) {
return true;
}
} else if (m_matchMode == StringMatch::StartsWith) {
if (strValue.startsWith(m_argument)) {
return true;
}
} else if (m_matchMode == StringMatch::EndsWith) {
if (strValue.endsWith(m_argument)) {
return true;
}
} else {
if (strValue.contains(m_argument)) {
return true;
Expand All @@ -223,6 +231,14 @@ QString TextFilterNode::toSql() const {
escapedArgument = escaper.escapeString(
kSqlLikeMatchAll + argument + kSqlLikeMatchAll);
break;
case StringMatch::StartsWith:
escapedArgument = escaper.escapeString(
kSqlLikeMatchAll + argument);
break;
case StringMatch::EndsWith:
escapedArgument = escaper.escapeString(
argument + kSqlLikeMatchAll);
break;
case StringMatch::Equals:
escapedArgument = escaper.escapeString(argument);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/library/searchquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const QString kMissingFieldSearchTerm = "\"\""; // "" searches for an empty stri
enum class StringMatch {
Contains = 0,
Equals,
StartsWith,
EndsWith,
};

class QueryNode {
Expand Down

0 comments on commit 94e6953

Please sign in to comment.