mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Add an option to limit tagging to a given set only.
This commit is contained in:
parent
9d76957c7f
commit
b52271e2b8
4 changed files with 53 additions and 21 deletions
|
@ -29,8 +29,8 @@ namespace din {
|
|||
set_options.add_options()
|
||||
//("switch,s", "Help message")
|
||||
//("option,o", po::value<std::string>()->default_value("default_value"), "Help message")
|
||||
//("option2", po::value<int>(), "Help message")
|
||||
("ids", po::value<std::string>(), "Comma-separated list of IDs of files to be tagged")
|
||||
("set,s", po::value<uint32_t>(), "Limit matching to files belonging to the specified set ID")
|
||||
;
|
||||
|
||||
po::options_description positional_options("Positional options");
|
||||
|
|
|
@ -82,16 +82,26 @@ int main (int parArgc, char* parArgv[]) {
|
|||
const auto master_tags_string = vm["tags"].as<std::string>();
|
||||
const std::vector<boost::string_ref> tags = dinlib::split_tags(master_tags_string);
|
||||
|
||||
din::OwnerSetInfo set_info;
|
||||
if (vm.count("set")) {
|
||||
set_info.is_valid = true;
|
||||
set_info.group_id = vm["set"].as<uint32_t>();
|
||||
}
|
||||
else {
|
||||
set_info.is_valid = false;
|
||||
set_info.group_id = 0;
|
||||
}
|
||||
|
||||
if (id_mode) {
|
||||
auto ids_string = dinlib::split_tags(vm["ids"].as<std::string>());
|
||||
std::vector<uint64_t> ids;
|
||||
ids.reserve(ids_string.size());
|
||||
std::transform(ids_string.begin(), ids_string.end(), std::back_inserter(ids), &lexical_cast<uint64_t, string_ref>);
|
||||
din::tag_files(settings.db, ids, tags);
|
||||
din::tag_files(settings.db, ids, tags, set_info);
|
||||
}
|
||||
else if (glob_mode) {
|
||||
const auto regexes(globs_to_regex_list(vm["globs"].as<std::vector<std::string>>()));
|
||||
din::tag_files(settings.db, regexes, tags);
|
||||
din::tag_files(settings.db, regexes, tags, set_info);
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
|
|
|
@ -21,31 +21,53 @@
|
|||
#include <ciso646>
|
||||
|
||||
namespace din {
|
||||
void tag_files (const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags) {
|
||||
void tag_files (const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2);";
|
||||
|
||||
conn.query(query, parTags, parFiles);
|
||||
if (parSet.is_valid) {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2) AND \"group_id\"=$3;";
|
||||
conn.query(query, parTags, parFiles, parSet.group_id);
|
||||
}
|
||||
else {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2);";
|
||||
conn.query(query, parTags, parFiles);
|
||||
}
|
||||
}
|
||||
|
||||
void tag_files (const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags) {
|
||||
void tag_files (const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
|
||||
if (parRegexes.size() == 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"path\" ~ $2;";
|
||||
conn.query(query, parTags, parRegexes.front());
|
||||
if (parSet.is_valid) {
|
||||
if (parRegexes.size() == 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"group_id\"=$2 AND \"path\" ~ $3;";
|
||||
conn.query(query, parTags, parSet.group_id, parRegexes.front());
|
||||
}
|
||||
else if (parRegexes.size() > 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"group_id\"=$2 AND \"path\" ~ ANY($3);";
|
||||
conn.query(query, parTags, parSet.group_id, parRegexes);
|
||||
}
|
||||
else if (parRegexes.size() == 0) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) WHERE \"group_id\"=$2 ORDER BY 1);";
|
||||
conn.query(query, parTags, parSet.group_id);
|
||||
}
|
||||
}
|
||||
else if (parRegexes.size() > 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"path\" ~ ANY($2);";
|
||||
conn.query(query, parTags, parRegexes);
|
||||
}
|
||||
else if (parRegexes.size() == 0) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1);";
|
||||
conn.query(query, parTags);
|
||||
else {
|
||||
if (parRegexes.size() == 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"path\" ~ $2;";
|
||||
conn.query(query, parTags, parRegexes.front());
|
||||
}
|
||||
else if (parRegexes.size() > 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"path\" ~ ANY($2);";
|
||||
conn.query(query, parTags, parRegexes);
|
||||
}
|
||||
else if (parRegexes.size() == 0) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1);";
|
||||
conn.query(query, parTags);
|
||||
}
|
||||
}
|
||||
}
|
||||
} //namespace din
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace din {
|
|||
bool is_valid;
|
||||
};
|
||||
|
||||
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags );
|
||||
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags );
|
||||
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
} //namespace din
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue