mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Implement locate_in_db().
This commit is contained in:
parent
5566b81b45
commit
d46cb322b9
3 changed files with 54 additions and 1 deletions
|
@ -239,7 +239,7 @@ namespace dindb {
|
|||
}
|
||||
|
||||
std::vector<LocatedItem> BackendRedis::locate_in_db (const std::string& parSearch, const TagList& parTags) {
|
||||
return std::vector<LocatedItem>();
|
||||
return dindb::locate_in_db(m_redis, parSearch, parTags);
|
||||
}
|
||||
|
||||
std::vector<LocatedItem> BackendRedis::locate_in_db (const mchlib::TigerHash& parSearch, const TagList& parTags) {
|
||||
|
|
|
@ -20,8 +20,30 @@
|
|||
#include "helpers/lexical_cast.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "dindexer-core/split_tags.hpp"
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
namespace dindb {
|
||||
namespace {
|
||||
void store_matching_paths (redis::Batch& parBatch, std::vector<LocatedItem>& parOut, std::vector<FileIDType>& parIDs, const boost::regex& parSearch) {
|
||||
using dinhelp::lexical_cast;
|
||||
assert(parIDs.size() == parBatch.replies().size());
|
||||
|
||||
parBatch.throw_if_failed();
|
||||
std::size_t id_index = 0;
|
||||
for (const auto& itm : parBatch.replies()) {
|
||||
const auto reply = redis::get_array(itm);
|
||||
const auto& path = redis::get_string(reply[0]);
|
||||
|
||||
if (boost::regex_search(path, parSearch)) {
|
||||
const auto group_id = lexical_cast<GroupIDType>(redis::get_string(reply[1]));
|
||||
parOut.push_back(LocatedItem{path, parIDs[id_index], group_id});
|
||||
}
|
||||
assert(id_index < parIDs.size());
|
||||
++id_index;
|
||||
}
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
std::vector<GroupIDType> find_all_sets (redis::Command& parRedis) {
|
||||
using dincore::split_and_trim;
|
||||
using dinhelp::lexical_cast;
|
||||
|
@ -32,4 +54,34 @@ namespace dindb {
|
|||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::vector<LocatedItem> locate_in_db (redis::Command& parRedis, const std::string& parSearch, const TagList& parTags) {
|
||||
using dincore::split_and_trim;
|
||||
using dinhelp::lexical_cast;
|
||||
|
||||
const boost::regex search(parSearch, boost::regex_constants::optimize | boost::regex_constants::nosubs | boost::regex_constants::perl);
|
||||
const int prefetch_count = 500;
|
||||
|
||||
std::vector<LocatedItem> retval;
|
||||
std::vector<FileIDType> ids;
|
||||
ids.reserve(prefetch_count);
|
||||
|
||||
int curr_count = 0;
|
||||
auto batch = parRedis.make_batch();
|
||||
for (const auto& itm : parRedis.scan(PROGRAM_NAME ":file:*")) {
|
||||
++curr_count;
|
||||
batch.run("HMGET", itm, "path", "group_id");
|
||||
ids.push_back(lexical_cast<FileIDType>(split_and_trim(itm, ':').back()));
|
||||
|
||||
if (curr_count == prefetch_count) {
|
||||
store_matching_paths(batch, retval, ids, search);
|
||||
batch.reset();
|
||||
curr_count = 0;
|
||||
ids.clear();
|
||||
}
|
||||
}
|
||||
if (curr_count)
|
||||
store_matching_paths(batch, retval, ids, search);
|
||||
return retval;
|
||||
}
|
||||
} //namespace dindb
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace redis {
|
|||
|
||||
namespace dindb {
|
||||
std::vector<GroupIDType> find_all_sets ( redis::Command& parRedis );
|
||||
std::vector<LocatedItem> locate_in_db ( redis::Command& parRedis, const std::string& parSearch, const TagList& parTags );
|
||||
} //namespace dindb
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue