mirror of https://github.com/milvus-io/milvus.git
time range search
Former-commit-id: 182c5c9db2d3aeaafc4d4878f060435c442b366cpull/191/head
parent
21a98c0e02
commit
aa591114c4
|
@ -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<DB_DATE> 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;
|
||||
|
|
|
@ -68,7 +68,14 @@ struct VecSearchResultList {
|
|||
1: list<VecSearchResult> 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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
#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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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<VecTimeRange> 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
|
||||
|
|
Loading…
Reference in New Issue