diff --git a/cpp/src/server/VecServiceTask.cpp b/cpp/src/server/VecServiceTask.cpp index 5af75723d0..8a778f0205 100644 --- a/cpp/src/server/VecServiceTask.cpp +++ b/cpp/src/server/VecServiceTask.cpp @@ -11,6 +11,7 @@ #include "utils/TimeRecorder.h" #include "db/DB.h" #include "db/Env.h" +#include "db/Meta.h" namespace zilliz { namespace vecwise { @@ -21,6 +22,9 @@ static const std::string DDL_DML_TASK_GROUP = "ddl_dml"; static const std::string VECTOR_UID = "uid"; +using DB_META = zilliz::vecwise::engine::meta::Meta; +using DB_DATE = zilliz::vecwise::engine::meta::DateT; + namespace { class DBWrapper { public: @@ -51,6 +55,12 @@ namespace { static DBWrapper db_wrapper; return db_wrapper.DB(); } + + DB_DATE MakeDbDate(const VecDateTime& dt) { + time_t t_t; + CommonUtil::ConvertTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, t_t); + return DB_META::GetDate(t_t); + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -556,10 +566,16 @@ ServerError SearchVectorTask::OnExecute() { uint64_t vec_count = GetTargetCount(); + std::vector dates; + for(const VecTimeRange& tr : filter_.time_ranges) { + dates.push_back(MakeDbDate(tr.time_begin)); + dates.push_back(MakeDbDate(tr.time_end)); + } + rc.Record("prepare input data"); engine::QueryResults results; - stat = DB()->search(group_id_, (size_t)top_k_, vec_count, vec_f.data(), results); + stat = DB()->search(group_id_, (size_t)top_k_, vec_count, vec_f.data(), dates, results); if(!stat.ok()) { SERVER_LOG_ERROR << "Engine failed: " << stat.ToString(); return SERVER_UNEXPECTED_ERROR; diff --git a/cpp/src/thrift/VectorService.thrift b/cpp/src/thrift/VectorService.thrift index 4608e288f2..fcd44879a5 100644 --- a/cpp/src/thrift/VectorService.thrift +++ b/cpp/src/thrift/VectorService.thrift @@ -68,7 +68,14 @@ struct VecSearchResultList { 1: list result_list; } - +/** + * second; Seconds. [0-60] (1 leap second) + * minute; Minutes. [0-59] + * hour; Hours. [0-23] + * day; Day. [1-31] + * month; Month. [0-11] + * year; Year - 1900. + */ struct VecDateTime { 1: required i32 year; 2: required i32 month; diff --git a/cpp/src/thrift/gen-py/zilliz/ttypes.py b/cpp/src/thrift/gen-py/zilliz/ttypes.py index 2c85d22c3f..e52e45d833 100644 --- a/cpp/src/thrift/gen-py/zilliz/ttypes.py +++ b/cpp/src/thrift/gen-py/zilliz/ttypes.py @@ -752,6 +752,13 @@ class VecSearchResultList(object): class VecDateTime(object): """ + second; Seconds. [0-60] (1 leap second) + minute; Minutes. [0-59] + hour; Hours. [0-23] + day; Day. [1-31] + month; Month. [0-11] + year; Year - 1900. + Attributes: - year - month diff --git a/cpp/src/utils/CommonUtil.cpp b/cpp/src/utils/CommonUtil.cpp index 083df0db73..e095c29151 100644 --- a/cpp/src/utils/CommonUtil.cpp +++ b/cpp/src/utils/CommonUtil.cpp @@ -150,6 +150,17 @@ std::string CommonUtil::GetExePath() { return exe_path; } +void CommonUtil::ConvertTime(int year, int month, int day, int hour, int minute, int second, time_t& t_t) { + tm t_m; + t_m.tm_year = year; + t_m.tm_mon = month; + t_m.tm_mday = day; + t_m.tm_hour = hour; + t_m.tm_min = minute; + t_m.tm_sec = second; + t_t = mktime(&t_m); +} + } } } diff --git a/cpp/src/utils/CommonUtil.h b/cpp/src/utils/CommonUtil.h index 5667b39e58..0a458cf9eb 100755 --- a/cpp/src/utils/CommonUtil.h +++ b/cpp/src/utils/CommonUtil.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include "Error.h" @@ -24,6 +25,8 @@ class CommonUtil { static ServerError DeleteDirectory(const std::string &path); static std::string GetExePath(); + + static void ConvertTime(int year, int month, int day, int hour, int minute, int second, time_t& t_t); }; } diff --git a/cpp/test_client/src/ClientTest.cpp b/cpp/test_client/src/ClientTest.cpp index 37f1764afc..3078105466 100644 --- a/cpp/test_client/src/ClientTest.cpp +++ b/cpp/test_client/src/ClientTest.cpp @@ -34,6 +34,15 @@ namespace { return str; } + void GetDate(int& year, int& month, int& day) { + time_t tt; + time( &tt ); + tm* t= gmtime( &tt ); + year = t->tm_year; + month = t->tm_mon; + day = t->tm_mday; + } + void GetServerAddress(std::string& address, int32_t& port, std::string& protocol) { server::ServerConfig& config = server::ServerConfig::GetInstance(); server::ConfigNode server_config = config.GetConfig(server::CONFIG_SERVER); @@ -174,10 +183,22 @@ TEST(SearchVector, CLIENT_TEST) { tensor.tensor.push_back((double) (i + anchor_index)); } + //build time range VecSearchResult res; VecSearchFilter filter; + VecTimeRange range; + VecDateTime date; + GetDate(date.year, date.month, date.day); + range.time_begin = date; + range.time_end = date; + std::vector time_ranges; + time_ranges.emplace_back(range); + filter.__set_time_ranges(time_ranges); + + //do search session.interface()->search_vector(res, GetGroupID(), top_k, tensor, filter); + //build result std::cout << "Search result: " << std::endl; for(VecSearchResultItem& item : res.result_list) { std::cout << "\t" << item.uid << std::endl; @@ -192,6 +213,17 @@ TEST(SearchVector, CLIENT_TEST) { if(!res.result_list.empty()) { ASSERT_TRUE(res.result_list[0].uid.find(std::to_string(anchor_index)) != std::string::npos); } + + //empty search + date.day > 0 ? date.day -= 1 : date.day += 1; + range.time_begin = date; + range.time_end = date; + time_ranges.clear(); + time_ranges.emplace_back(range); + filter.__set_time_ranges(time_ranges); + session.interface()->search_vector(res, GetGroupID(), top_k, tensor, filter); + + ASSERT_EQ(res.result_list.size(), 0); } //search binary vector