Skip to content

Commit

Permalink
Merge branch 'feature/SDK-3775-search-nodes-by-tag' into 'develop'
Browse files Browse the repository at this point in the history
SDK-3775. Add support for search nodes by tag

Closes SDK-3775

See merge request sdk/sdk!5445
  • Loading branch information
alber2510 committed Apr 16, 2024
2 parents 6fc1394 + 58b08ea commit b9cafcd
Show file tree
Hide file tree
Showing 12 changed files with 358 additions and 165 deletions.
11 changes: 4 additions & 7 deletions include/mega/db/sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

#include <sqlite3.h>

// Include ICU headers
#include <unicode/uchar.h>

namespace mega {

class MEGA_API SqliteDbTable : public DbTable
Expand Down Expand Up @@ -158,10 +155,6 @@ class MEGA_API SqliteAccountState : public SqliteDbTable, public DBTableNodes
// If the progress callback returns non-zero, the operation is interrupted
static int progressHandler(void *);
static void userRegexp(sqlite3_context* context, int argc, sqlite3_value** argv);
static int icuLikeCompare(const uint8_t *zPattern, /* LIKE pattern */
const uint8_t *zString, /* The UTF-8 string to compare against */
const UChar32 uEsc /* The escape character */
);

// Method called when query use method 'ismimetype'
// It checks if received mimetype is the same as extension extracted from file name
Expand All @@ -174,6 +167,10 @@ class MEGA_API SqliteAccountState : public SqliteDbTable, public DBTableNodes
// Check if string (pattern - argv[0]) is contained at data base column from type text (argv[1])
static void userIsContained(sqlite3_context* context, int argc, sqlite3_value** argv);

// Check if a tag (string - argv[0]) is contained in the stored list of tags
//(string with the tags delimited by TAG_DELIMITER - argv[1]).
static void userMatchTag(sqlite3_context* context, int argc, sqlite3_value** argv);

private:
// Iterate over a SQL query row by row and fill the map
// Allow at least the following containers:
Expand Down
2 changes: 2 additions & 0 deletions include/mega/megaclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ class MEGA_API MegaClient
static constexpr char NODE_ATTRIBUTE_DESCRIPTION[] = "des";
static constexpr char NODE_ATTRIBUTE_TAGS[] = "t";
static constexpr char TAG_DELIMITER = ',';
static constexpr uint32_t MAX_NUMBER_TAGS = 10;
static constexpr uint32_t MAX_TAGS_SIZE = 3000;

// update node attributes
error setattr(std::shared_ptr<Node>, attr_map&& updates, CommandSetAttr::Completion&& c, bool canChangeVault);
Expand Down
3 changes: 3 additions & 0 deletions include/mega/nodemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class NodeSearchFilter
mModificationLowerLimit = f.byModificationTimeLowerLimit();
mModificationUpperLimit = f.byModificationTimeUpperLimit();
mDescriptionFilter = f.byDescription();
mTagFilter = f.byTag();
}

void byAncestors(std::vector<handle>&& ancs) { assert(ancs.size() == 3); mLocationHandles.swap(ancs); }
Expand All @@ -80,6 +81,7 @@ class NodeSearchFilter
int64_t byModificationTimeLowerLimit() const { return mModificationLowerLimit; }
int64_t byModificationTimeUpperLimit() const { return mModificationUpperLimit; }
const std::string& byDescription() const { return mDescriptionFilter; }
const std::string& byTag() const { return mTagFilter; }

private:
std::string mNameFilter;
Expand All @@ -93,6 +95,7 @@ class NodeSearchFilter
int64_t mModificationLowerLimit = 0;
int64_t mModificationUpperLimit = 0;
std::string mDescriptionFilter;
std::string mTagFilter;
};

class NodeSearchPage
Expand Down
11 changes: 11 additions & 0 deletions include/mega/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "mega/mega_utf8proc.h"
#undef SSIZE_MAX

// Include ICU headers
#include <unicode/uchar.h>

namespace mega {
// convert 1...8 character ID to int64 integer (endian agnostic)
#define MAKENAMEID1(a) (nameid)(a)
Expand Down Expand Up @@ -1099,6 +1102,14 @@ static constexpr char ESCAPE_CHARACTER = '\\';

std::string escapeWildCards(const std::string& pattern);

std::set<std::string>::iterator getTagPosition(std::set<std::string>& tokens, const std::string& tag);

// Check if two string (possible multibyte characters) are equal without take account if they are lower or higher case
// 1 if they are equal
int icuLikeCompare(const uint8_t* zPattern, /* LIKE pattern */
const uint8_t* zString, /* The UTF-8 string to compare against */
const UChar32 uEsc); /* The escape character */

// Get the current process ID
unsigned long getCurrentPid();

Expand Down
38 changes: 32 additions & 6 deletions include/megaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -9501,6 +9501,23 @@ class MegaSearchFilter
*/
virtual void byModificationTime(int64_t lowerLimit, int64_t upperLimit);

/**
* @brief Set option for filtering by contains in description.
*
* @param searchString Contains string to be searched at nodes description
*/
virtual void byDescription(const char* searchString);

/**
* @brief Set option for filtering by tag
*
* @note ',' is an invalid character, it shouldn't be used as part of searchString. If used,
* empty list will be returned
*
* @param searchString Contains string to be searched at nodes tags
*/
virtual void byTag(const char* searchString);

/**
* @brief Return the string used for filtering by name.
*
Expand Down Expand Up @@ -9572,18 +9589,18 @@ class MegaSearchFilter
virtual int64_t byModificationTimeUpperLimit() const;

/**
* @brief Set option for filtering by contains in description.
* @brief Return the string used for filtering by description.
*
* @param searchString Contains string to be searched at nodes description
* @return string set for filtering by description, or empty string ("") if not set
*/
virtual void byDescription(const char* searchString);
virtual const char* byDescription() const;

/**
* @brief Return the string used for filtering by description.
* @brief Return the string used for filtering by tag.
*
* @return string set for filtering by description, or empty string ("") if not set
* @return string set for filtering by tag, or empty string ("") if not set
*/
virtual const char* byDescription() const;
virtual const char* byTag() const;
};

/**
Expand Down Expand Up @@ -13666,8 +13683,14 @@ class MegaApi
* ',' is an invalid character to be used in a tag. If it is contained in the tag,
* onRequestFinish will be called with the error code MegaError::API_EARGS.
*
* If the length of all tags is higher than 3000 onRequestFinish will be called with
* the error code MegaError::API_EARGS
*
* If tag already exists, onRequestFinish will be called with the error code MegaError::API_EEXISTS
*
* If number of tags exceed the maximum number of tags (10),
* onRequestFinish will be called with the error code MegaError::API_ETOOMANY
*
* If the MEGA account is a business account and its status is expired, onRequestFinish will
* be called with the error code MegaError::API_EBUSINESSPASTDUE.
*
Expand Down Expand Up @@ -13710,6 +13733,9 @@ class MegaApi
* ',' is an invalid character to be used in a tag. If it is contained in the tag,
* onRequestFinish will be called with the error code MegaError::API_EARGS.
*
* If the length of all tags is higher than 3000 characters onRequestFinish will be called with
* the error code MegaError::API_EARGS
*
* If newTag already exists, onRequestFinish will be called with the error code MegaError::API_EEXISTS
* If oldTag doesn't exist, onRequestFinish will be called with the error code MegaError::API_ENOENT
*
Expand Down
5 changes: 4 additions & 1 deletion include/megaapi_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2805,6 +2805,8 @@ class MegaSearchFilterPrivate : public MegaSearchFilter
void byLocation(int locationType) override;
void byCreationTime(int64_t lowerLimit, int64_t upperLimit) override;
void byModificationTime(int64_t lowerLimit, int64_t upperLimit) override;
void byDescription(const char* searchString) override;
void byTag(const char* searchString) override;

const char* byName() const override { return mNameFilter.c_str(); }
int byNodeType() const override { return mNodeType; }
Expand All @@ -2816,8 +2818,8 @@ class MegaSearchFilterPrivate : public MegaSearchFilter
int64_t byCreationTimeUpperLimit() const override { return mCreationUpperLimit; }
int64_t byModificationTimeLowerLimit() const override { return mModificationLowerLimit; }
int64_t byModificationTimeUpperLimit() const override { return mModificationUpperLimit; }
void byDescription(const char* searchString) override;
const char* byDescription() const override { return mDescriptionFilter.c_str(); }
const char* byTag() const override { return mTag.c_str(); }

private:
std::string mNameFilter;
Expand All @@ -2831,6 +2833,7 @@ class MegaSearchFilterPrivate : public MegaSearchFilter
int64_t mModificationLowerLimit = 0;
int64_t mModificationUpperLimit = 0;
std::string mDescriptionFilter;
std::string mTag;
};

class MegaSearchPagePrivate : public MegaSearchPage
Expand Down
Loading

0 comments on commit b9cafcd

Please sign in to comment.