mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Implement locate_in_db() by hash.
This commit is contained in:
parent
01be1a94e5
commit
afb2e68849
5 changed files with 71 additions and 2 deletions
|
@ -250,7 +250,7 @@ namespace dindb {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<LocatedItem> BackendRedis::locate_in_db (const mchlib::TigerHash& parSearch, const TagList& parTags) {
|
std::vector<LocatedItem> BackendRedis::locate_in_db (const mchlib::TigerHash& parSearch, const TagList& parTags) {
|
||||||
return std::vector<LocatedItem>();
|
return dindb::locate_in_db(m_redis, parSearch, parTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<LocatedSet> BackendRedis::locate_sets_in_db (const std::string& parSearch, bool parCaseInsensitive) {
|
std::vector<LocatedSet> BackendRedis::locate_sets_in_db (const std::string& parSearch, bool parCaseInsensitive) {
|
||||||
|
|
|
@ -20,9 +20,13 @@
|
||||||
#include "helpers/lexical_cast.hpp"
|
#include "helpers/lexical_cast.hpp"
|
||||||
#include "dindexerConfig.h"
|
#include "dindexerConfig.h"
|
||||||
#include "dindexer-core/split_tags.hpp"
|
#include "dindexer-core/split_tags.hpp"
|
||||||
|
#include "dindexer-machinery/tiger.hpp"
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <boost/range/adaptor/filtered.hpp>
|
||||||
|
#include <boost/range/adaptor/transformed.hpp>
|
||||||
|
#include <boost/iterator/zip_iterator.hpp>
|
||||||
|
|
||||||
namespace dindb {
|
namespace dindb {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -62,6 +66,20 @@ namespace dindb {
|
||||||
++id_index;
|
++id_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//See: http://stackoverflow.com/questions/12552277/whats-the-best-way-to-iterate-over-two-or-more-containers-simultaneously/12553437#12553437
|
||||||
|
//(referenced from http://stackoverflow.com/questions/16982190/c-use-boost-range-transformed-adaptor-with-binary-function)
|
||||||
|
//What became of this? http://marc.info/?l=boost-users&m=129619765731342
|
||||||
|
template <typename... Conts>
|
||||||
|
auto zip_range (Conts&... parConts) -> decltype(boost::make_iterator_range(
|
||||||
|
boost::make_zip_iterator(boost::make_tuple(parConts.begin()...)),
|
||||||
|
boost::make_zip_iterator(boost::make_tuple(parConts.end()...)))
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
boost::make_zip_iterator(boost::make_tuple(parConts.begin()...)),
|
||||||
|
boost::make_zip_iterator(boost::make_tuple(parConts.end()...))
|
||||||
|
};
|
||||||
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
std::vector<GroupIDType> find_all_sets (redis::IncRedis& parRedis) {
|
std::vector<GroupIDType> find_all_sets (redis::IncRedis& parRedis) {
|
||||||
|
@ -104,4 +122,49 @@ namespace dindb {
|
||||||
store_matching_paths(batch, retval, ids, search, parTags);
|
store_matching_paths(batch, retval, ids, search, parTags);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<LocatedItem> locate_in_db (redis::IncRedis& parRedis, const mchlib::TigerHash& parSearch, const TagList& parTags) {
|
||||||
|
using boost::adaptors::filtered;
|
||||||
|
using boost::adaptors::transformed;
|
||||||
|
using boost::tuple;
|
||||||
|
using boost::make_tuple;
|
||||||
|
using redis::get_string;
|
||||||
|
using redis::Reply;
|
||||||
|
using std::vector;
|
||||||
|
using dinhelp::lexical_cast;
|
||||||
|
|
||||||
|
const auto hash_key = PROGRAM_NAME ":hash:" + mchlib::tiger_to_string(parSearch, false);
|
||||||
|
const auto file_ids = parRedis.smembers(hash_key);
|
||||||
|
|
||||||
|
vector<std::string> ids;
|
||||||
|
if (file_ids) {
|
||||||
|
auto batch = parRedis.make_batch();
|
||||||
|
for (auto&& file_id : *file_ids) {
|
||||||
|
if (not file_id)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto file_key = PROGRAM_NAME ":file:" + *file_id;
|
||||||
|
ids.emplace_back(std::move(*file_id));
|
||||||
|
batch.hmget(file_key, "path", "group_id", "tags");
|
||||||
|
}
|
||||||
|
batch.throw_if_failed();
|
||||||
|
|
||||||
|
assert(batch.replies().size() == ids.size());
|
||||||
|
return boost::copy_range<vector<LocatedItem>>(
|
||||||
|
zip_range(batch.replies(), ids) |
|
||||||
|
transformed([](const tuple<Reply, std::string>& r)
|
||||||
|
{ return make_tuple(redis::get_array(r.get<0>()), r.get<1>()); }
|
||||||
|
) |
|
||||||
|
filtered([&parTags](const tuple<vector<Reply>, std::string>& t)
|
||||||
|
{ return parTags.empty() or all_tags_match(parTags, get_string(t.get<0>()[2])); }
|
||||||
|
) |
|
||||||
|
transformed([&ids](const tuple<vector<Reply>, std::string>& t)
|
||||||
|
{ return LocatedItem{ get_string(t.get<0>()[0]), lexical_cast<FileIDType>(t.get<1>()), lexical_cast<GroupIDType>(get_string(t.get<0>()[1])) }; }
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::vector<LocatedItem>();
|
||||||
|
}
|
||||||
|
}
|
||||||
} //namespace dindb
|
} //namespace dindb
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace redis {
|
||||||
namespace dindb {
|
namespace dindb {
|
||||||
std::vector<GroupIDType> find_all_sets ( redis::IncRedis& parRedis );
|
std::vector<GroupIDType> find_all_sets ( redis::IncRedis& parRedis );
|
||||||
std::vector<LocatedItem> locate_in_db ( redis::IncRedis& parRedis, const std::string& parSearch, const TagList& parTags );
|
std::vector<LocatedItem> locate_in_db ( redis::IncRedis& parRedis, const std::string& parSearch, const TagList& parTags );
|
||||||
|
std::vector<LocatedItem> locate_in_db ( redis::IncRedis& parRedis, const mchlib::TigerHash& parSearch, const TagList& parTags );
|
||||||
} //namespace dindb
|
} //namespace dindb
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
namespace redis {
|
namespace redis {
|
||||||
namespace {
|
namespace {
|
||||||
inline IncRedis::opt_string optional_string ( const Reply& parReply ) a_always_inline;
|
inline IncRedis::opt_string optional_string ( const Reply& parReply ) a_always_inline;
|
||||||
inline IncRedis::opt_string_list optional_string_list ( const Reply& parReply ) a_always_inline;
|
IncRedis::opt_string_list optional_string_list ( const Reply& parReply );
|
||||||
|
|
||||||
IncRedis::opt_string optional_string (const Reply& parReply) {
|
IncRedis::opt_string optional_string (const Reply& parReply) {
|
||||||
assert(parReply.which() == RedisVariantType_Nil or parReply.which() == RedisVariantType_String);
|
assert(parReply.which() == RedisVariantType_Nil or parReply.which() == RedisVariantType_String);
|
||||||
|
@ -115,6 +115,10 @@ namespace redis {
|
||||||
return optional_string(m_command.run("SRANDMEMBER", parKey));
|
return optional_string(m_command.run("SRANDMEMBER", parKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto IncRedis::smembers (boost::string_ref parKey) -> opt_string_list {
|
||||||
|
return optional_string_list(m_command.run("SMEMBERS", parKey));
|
||||||
|
}
|
||||||
|
|
||||||
bool IncRedis::script_flush() {
|
bool IncRedis::script_flush() {
|
||||||
const auto ret = get<StatusString>(m_command.run("SCRIPT", "FLUSH"));
|
const auto ret = get<StatusString>(m_command.run("SCRIPT", "FLUSH"));
|
||||||
return ret.is_ok();
|
return ret.is_ok();
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace redis {
|
||||||
//Set
|
//Set
|
||||||
opt_string_list srandmember ( boost::string_ref parKey, int parCount );
|
opt_string_list srandmember ( boost::string_ref parKey, int parCount );
|
||||||
opt_string srandmember ( boost::string_ref parKey );
|
opt_string srandmember ( boost::string_ref parKey );
|
||||||
|
opt_string_list smembers ( boost::string_ref parKey );
|
||||||
|
|
||||||
//Script
|
//Script
|
||||||
bool script_flush ( void );
|
bool script_flush ( void );
|
||||||
|
|
Loading…
Add table
Reference in a new issue