convert tab to spaces
This commit is contained in:
parent
79f2d07c15
commit
fb6a8f3d02
@ -22,100 +22,100 @@ BoolQueryParser::BoolQueryParser(uint32_t a, Json::Value& v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BoolQueryParser::~BoolQueryParser(){
|
BoolQueryParser::~BoolQueryParser(){
|
||||||
if(NULL != range_query_parser){
|
if(NULL != range_query_parser){
|
||||||
delete range_query_parser;
|
delete range_query_parser;
|
||||||
}
|
}
|
||||||
if(NULL != term_query_parser){
|
if(NULL != term_query_parser){
|
||||||
delete term_query_parser;
|
delete term_query_parser;
|
||||||
}
|
}
|
||||||
if(NULL != match_query_parser){
|
if(NULL != match_query_parser){
|
||||||
delete match_query_parser;
|
delete match_query_parser;
|
||||||
}
|
}
|
||||||
if(NULL != geo_query_parser){
|
if(NULL != geo_query_parser){
|
||||||
delete geo_query_parser;
|
delete geo_query_parser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int BoolQueryParser::DoJobByType(Json::Value& value, uint32_t type, QueryParserRes* query_parser_res){
|
int BoolQueryParser::DoJobByType(Json::Value& value, uint32_t type, QueryParserRes* query_parser_res){
|
||||||
if(value.isMember(TERM)){
|
if(value.isMember(TERM)){
|
||||||
term_query_parser = new TermQueryParser(appid, value[TERM]);
|
term_query_parser = new TermQueryParser(appid, value[TERM]);
|
||||||
return term_query_parser->ParseContent(query_parser_res, type);
|
return term_query_parser->ParseContent(query_parser_res, type);
|
||||||
} else if(value.isMember(MATCH)){
|
} else if(value.isMember(MATCH)){
|
||||||
match_query_parser = new MatchQueryParser(appid, value[MATCH]);
|
match_query_parser = new MatchQueryParser(appid, value[MATCH]);
|
||||||
return match_query_parser->ParseContent(query_parser_res, type);
|
return match_query_parser->ParseContent(query_parser_res, type);
|
||||||
} else if(value.isMember(RANGE)){
|
} else if(value.isMember(RANGE)){
|
||||||
range_query_parser = new RangeQueryParser(appid, value[RANGE]);
|
range_query_parser = new RangeQueryParser(appid, value[RANGE]);
|
||||||
return range_query_parser->ParseContent(query_parser_res, type);
|
return range_query_parser->ParseContent(query_parser_res, type);
|
||||||
} else if(value.isMember(GEODISTANCE)){
|
} else if(value.isMember(GEODISTANCE)){
|
||||||
geo_query_parser = new GeoDistanceParser(appid, value[GEODISTANCE]);
|
geo_query_parser = new GeoDistanceParser(appid, value[GEODISTANCE]);
|
||||||
return geo_query_parser->ParseContent(query_parser_res);
|
return geo_query_parser->ParseContent(query_parser_res);
|
||||||
} else {
|
} else {
|
||||||
string err_msg = "BoolQueryParser only support term/match/range/geo_distance!";
|
string err_msg = "BoolQueryParser only support term/match/range/geo_distance!";
|
||||||
log_error(err_msg.c_str());
|
log_error(err_msg.c_str());
|
||||||
query_parser_res->ErrMsg() = err_msg;
|
query_parser_res->ErrMsg() = err_msg;
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BoolQueryParser::ParseContent(QueryParserRes* query_parser_res){
|
int BoolQueryParser::ParseContent(QueryParserRes* query_parser_res){
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if(value.isMember(MUST)){
|
if(value.isMember(MUST)){
|
||||||
int type = ANDKEY;
|
int type = ANDKEY;
|
||||||
Json::Value must = value[MUST];
|
Json::Value must = value[MUST];
|
||||||
if(must.isArray()){
|
if(must.isArray()){
|
||||||
for(int i = 0; i < (int)must.size(); i++){
|
for(int i = 0; i < (int)must.size(); i++){
|
||||||
ret = DoJobByType(must[i], type, query_parser_res);
|
ret = DoJobByType(must[i], type, query_parser_res);
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
log_error("DoJobByType error!");
|
log_error("DoJobByType error!");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (must.isObject()){
|
} else if (must.isObject()){
|
||||||
ret = DoJobByType(must, type, query_parser_res);
|
ret = DoJobByType(must, type, query_parser_res);
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
log_error("DoJobByType error!");
|
log_error("DoJobByType error!");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value.isMember(SHOULD)){
|
if (value.isMember(SHOULD)){
|
||||||
int type = ORKEY;
|
int type = ORKEY;
|
||||||
Json::Value should = value[SHOULD];
|
Json::Value should = value[SHOULD];
|
||||||
if(should.isArray()){
|
if(should.isArray()){
|
||||||
for(int i = 0; i < (int)should.size(); i++){
|
for(int i = 0; i < (int)should.size(); i++){
|
||||||
ret = DoJobByType(should[i], type, query_parser_res);
|
ret = DoJobByType(should[i], type, query_parser_res);
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
log_error("DoJobByType error!");
|
log_error("DoJobByType error!");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (should.isObject()){
|
} else if (should.isObject()){
|
||||||
ret = DoJobByType(should, type, query_parser_res);
|
ret = DoJobByType(should, type, query_parser_res);
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
log_error("DoJobByType error!");
|
log_error("DoJobByType error!");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value.isMember(MUST_NOT)){
|
if (value.isMember(MUST_NOT)){
|
||||||
int type = INVERTKEY;
|
int type = INVERTKEY;
|
||||||
Json::Value must_not = value[MUST_NOT];
|
Json::Value must_not = value[MUST_NOT];
|
||||||
if(must_not.isArray()){
|
if(must_not.isArray()){
|
||||||
for(int i = 0; i < (int)must_not.size(); i++){
|
for(int i = 0; i < (int)must_not.size(); i++){
|
||||||
ret = DoJobByType(must_not[i], type, query_parser_res);
|
ret = DoJobByType(must_not[i], type, query_parser_res);
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
log_error("DoJobByType error!");
|
log_error("DoJobByType error!");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (must_not.isObject()) {
|
} else if (must_not.isObject()) {
|
||||||
ret = DoJobByType(must_not, type, query_parser_res);
|
ret = DoJobByType(must_not, type, query_parser_res);
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
log_error("DoJobByType error!");
|
log_error("DoJobByType error!");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -28,21 +28,21 @@ class GeoDistanceParser;
|
|||||||
class BoolQueryParser : public QueryParser
|
class BoolQueryParser : public QueryParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BoolQueryParser(uint32_t a, Json::Value& v);
|
BoolQueryParser(uint32_t a, Json::Value& v);
|
||||||
~BoolQueryParser();
|
~BoolQueryParser();
|
||||||
|
|
||||||
int ParseContent(QueryParserRes* query_parser_res);
|
int ParseContent(QueryParserRes* query_parser_res);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int DoJobByType(Json::Value& value, uint32_t type, QueryParserRes* query_parser_res);
|
int DoJobByType(Json::Value& value, uint32_t type, QueryParserRes* query_parser_res);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t appid;
|
uint32_t appid;
|
||||||
Json::Value value;
|
Json::Value value;
|
||||||
RangeQueryParser* range_query_parser;
|
RangeQueryParser* range_query_parser;
|
||||||
TermQueryParser* term_query_parser;
|
TermQueryParser* term_query_parser;
|
||||||
MatchQueryParser* match_query_parser;
|
MatchQueryParser* match_query_parser;
|
||||||
GeoDistanceParser* geo_query_parser;
|
GeoDistanceParser* geo_query_parser;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -18,28 +18,28 @@ GeoDistanceParser::~GeoDistanceParser(){
|
|||||||
|
|
||||||
vector<double> splitDouble(const string& src, string separate_character)
|
vector<double> splitDouble(const string& src, string separate_character)
|
||||||
{
|
{
|
||||||
vector<double> strs;
|
vector<double> strs;
|
||||||
|
|
||||||
//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符
|
//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符
|
||||||
int separate_characterLen = separate_character.size();
|
int separate_characterLen = separate_character.size();
|
||||||
int lastPosition = 0, index = -1;
|
int lastPosition = 0, index = -1;
|
||||||
string str;
|
string str;
|
||||||
double pos = 0;
|
double pos = 0;
|
||||||
while (-1 != (index = src.find(separate_character, lastPosition)))
|
while (-1 != (index = src.find(separate_character, lastPosition)))
|
||||||
{
|
{
|
||||||
if (src.substr(lastPosition, index - lastPosition) != " ") {
|
if (src.substr(lastPosition, index - lastPosition) != " ") {
|
||||||
str = src.substr(lastPosition, index - lastPosition);
|
str = src.substr(lastPosition, index - lastPosition);
|
||||||
pos = atof(str.c_str());
|
pos = atof(str.c_str());
|
||||||
strs.push_back(pos);
|
strs.push_back(pos);
|
||||||
}
|
}
|
||||||
lastPosition = index + separate_characterLen;
|
lastPosition = index + separate_characterLen;
|
||||||
}
|
|
||||||
string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容
|
|
||||||
if (!lastString.empty() && lastString != " "){
|
|
||||||
pos = atof(lastString.c_str());
|
|
||||||
strs.push_back(pos);//如果最后一个分隔符后还有内容就入队
|
|
||||||
}
|
}
|
||||||
return strs;
|
string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容
|
||||||
|
if (!lastString.empty() && lastString != " "){
|
||||||
|
pos = atof(lastString.c_str());
|
||||||
|
strs.push_back(pos);//如果最后一个分隔符后还有内容就入队
|
||||||
|
}
|
||||||
|
return strs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetErrMsg(QueryParserRes* query_parser_res, string err_msg){
|
void SetErrMsg(QueryParserRes* query_parser_res, string err_msg){
|
||||||
@ -51,9 +51,9 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
vector<FieldInfo> fieldInfos;
|
vector<FieldInfo> fieldInfos;
|
||||||
double distance = 0;
|
double distance = 0;
|
||||||
string fieldname;
|
string fieldname;
|
||||||
Json::Value::Members member = value.getMemberNames();
|
Json::Value::Members member = value.getMemberNames();
|
||||||
Json::Value::Members::iterator iter = member.begin();
|
Json::Value::Members::iterator iter = member.begin();
|
||||||
for(; iter != member.end(); iter++){
|
for(; iter != member.end(); iter++){
|
||||||
Json::Value geo_value = value[*iter];
|
Json::Value geo_value = value[*iter];
|
||||||
if(DISTANCE == *iter){
|
if(DISTANCE == *iter){
|
||||||
if(geo_value.isString()){
|
if(geo_value.isString()){
|
||||||
@ -72,7 +72,7 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
geo.lon = res[1];
|
geo.lon = res[1];
|
||||||
} else {
|
} else {
|
||||||
SetErrMsg(query_parser_res, "GeoDistanceParser format error.");
|
SetErrMsg(query_parser_res, "GeoDistanceParser format error.");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
} else if (geo_value.isArray()){
|
} else if (geo_value.isArray()){
|
||||||
if(geo_value.size() >= 2){
|
if(geo_value.size() >= 2){
|
||||||
@ -84,24 +84,24 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SetErrMsg(query_parser_res, "GeoDistanceParser format error.");
|
SetErrMsg(query_parser_res, "GeoDistanceParser format error.");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
} else if (geo_value.isObject()){
|
} else if (geo_value.isObject()){
|
||||||
if(geo_value.isMember("lat") && geo_value["lat"].isDouble()){
|
if(geo_value.isMember("lat") && geo_value["lat"].isDouble()){
|
||||||
geo.lat = geo_value["lat"].asDouble();
|
geo.lat = geo_value["lat"].asDouble();
|
||||||
} else {
|
} else {
|
||||||
SetErrMsg(query_parser_res, "GeoDistanceParser lat format error.");
|
SetErrMsg(query_parser_res, "GeoDistanceParser lat format error.");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
if(geo_value.isMember("lon") && geo_value["lon"].isDouble()){
|
if(geo_value.isMember("lon") && geo_value["lon"].isDouble()){
|
||||||
geo.lon = geo_value["lon"].asDouble();
|
geo.lon = geo_value["lon"].asDouble();
|
||||||
} else {
|
} else {
|
||||||
SetErrMsg(query_parser_res, "GeoDistanceParser lon format error.");
|
SetErrMsg(query_parser_res, "GeoDistanceParser lon format error.");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SetErrMsg(query_parser_res, "GeoDistanceParser error, value is not string/array/object.");
|
SetErrMsg(query_parser_res, "GeoDistanceParser error, value is not string/array/object.");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,24 +110,24 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
}
|
}
|
||||||
vector<string> gisCode = GetArroundGeoHash(geo, distance, GEO_PRECISION);
|
vector<string> gisCode = GetArroundGeoHash(geo, distance, GEO_PRECISION);
|
||||||
if(gisCode.size() > 0){
|
if(gisCode.size() > 0){
|
||||||
vector<FieldInfo> fieldInfos;
|
vector<FieldInfo> fieldInfos;
|
||||||
uint32_t segment_tag = 0;
|
uint32_t segment_tag = 0;
|
||||||
FieldInfo fieldInfo;
|
FieldInfo fieldInfo;
|
||||||
uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
||||||
if (field != 0 && segment_tag == 0) {
|
if (field != 0 && segment_tag == 0) {
|
||||||
query_parser_res->HasGis() = 1;
|
query_parser_res->HasGis() = 1;
|
||||||
for (size_t index = 0; index < gisCode.size(); index++) {
|
for (size_t index = 0; index < gisCode.size(); index++) {
|
||||||
FieldInfo info;
|
FieldInfo info;
|
||||||
info.field = fieldInfo.field;
|
info.field = fieldInfo.field;
|
||||||
info.field_type = fieldInfo.field_type;
|
info.field_type = fieldInfo.field_type;
|
||||||
info.segment_tag = fieldInfo.segment_tag;
|
info.segment_tag = fieldInfo.segment_tag;
|
||||||
info.word = gisCode[index];
|
info.word = gisCode[index];
|
||||||
fieldInfos.push_back(info);
|
fieldInfos.push_back(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fieldInfos.size() != 0) {
|
if (fieldInfos.size() != 0) {
|
||||||
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
}
|
}
|
||||||
stringstream sslat;
|
stringstream sslat;
|
||||||
stringstream sslon;
|
stringstream sslon;
|
||||||
sslat << geo.lat;
|
sslat << geo.lat;
|
||||||
@ -135,6 +135,6 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
sslon << geo.lon;
|
sslon << geo.lon;
|
||||||
query_parser_res->Longitude() = sslon.str();
|
query_parser_res->Longitude() = sslon.str();
|
||||||
query_parser_res->Distance() = distance;
|
query_parser_res->Distance() = distance;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -26,12 +26,12 @@ class GeoDistanceParser : public QueryParser
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeoDistanceParser(uint32_t a, Json::Value& v);
|
GeoDistanceParser(uint32_t a, Json::Value& v);
|
||||||
~GeoDistanceParser();
|
~GeoDistanceParser();
|
||||||
int ParseContent(QueryParserRes* query_parser_res);
|
int ParseContent(QueryParserRes* query_parser_res);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t appid;
|
uint32_t appid;
|
||||||
Json::Value value;
|
Json::Value value;
|
||||||
GeoPoint geo;
|
GeoPoint geo;
|
||||||
double distance;
|
double distance;
|
||||||
};
|
};
|
||||||
|
@ -18,49 +18,49 @@ int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
|
|
||||||
int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
|
int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
|
||||||
vector<FieldInfo> fieldInfos;
|
vector<FieldInfo> fieldInfos;
|
||||||
Json::Value::Members member = value.getMemberNames();
|
Json::Value::Members member = value.getMemberNames();
|
||||||
Json::Value::Members::iterator iter = member.begin();
|
Json::Value::Members::iterator iter = member.begin();
|
||||||
string fieldname;
|
string fieldname;
|
||||||
Json::Value field_value;
|
Json::Value field_value;
|
||||||
if(iter != member.end()){ // 一个match下只对应一个字段
|
if(iter != member.end()){ // 一个match下只对应一个字段
|
||||||
fieldname = *iter;
|
fieldname = *iter;
|
||||||
field_value = value[fieldname];
|
field_value = value[fieldname];
|
||||||
} else {
|
} else {
|
||||||
log_error("TermQueryParser error, value is null");
|
log_error("TermQueryParser error, value is null");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
uint32_t segment_tag = 0;
|
uint32_t segment_tag = 0;
|
||||||
FieldInfo fieldInfo;
|
FieldInfo fieldInfo;
|
||||||
uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
||||||
if (field != 0 && segment_tag == 1)
|
if (field != 0 && segment_tag == 1)
|
||||||
{
|
{
|
||||||
string split_data = SplitManager::Instance()->split(field_value.asString(), appid);
|
string split_data = SplitManager::Instance()->split(field_value.asString(), appid);
|
||||||
log_debug("split_data: %s", split_data.c_str());
|
log_debug("split_data: %s", split_data.c_str());
|
||||||
vector<string> split_datas = splitEx(split_data, "|");
|
vector<string> split_datas = splitEx(split_data, "|");
|
||||||
for(size_t index = 0; index < split_datas.size(); index++)
|
for(size_t index = 0; index < split_datas.size(); index++)
|
||||||
{
|
{
|
||||||
FieldInfo info;
|
FieldInfo info;
|
||||||
info.field = fieldInfo.field;
|
info.field = fieldInfo.field;
|
||||||
info.field_type = fieldInfo.field_type;
|
info.field_type = fieldInfo.field_type;
|
||||||
info.word = split_datas[index];
|
info.word = split_datas[index];
|
||||||
info.segment_tag = fieldInfo.segment_tag;
|
info.segment_tag = fieldInfo.segment_tag;
|
||||||
fieldInfos.push_back(info);
|
fieldInfos.push_back(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (field != 0)
|
else if (field != 0)
|
||||||
{
|
{
|
||||||
fieldInfo.word = field_value.asString();
|
fieldInfo.word = field_value.asString();
|
||||||
fieldInfos.push_back(fieldInfo);
|
fieldInfos.push_back(fieldInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fieldInfos.size() != 0){
|
if(fieldInfos.size() != 0){
|
||||||
if(type == ORKEY){
|
if(type == ORKEY){
|
||||||
query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
} else if(type == ANDKEY){
|
} else if(type == ANDKEY){
|
||||||
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
} else if(type == INVERTKEY){
|
} else if(type == INVERTKEY){
|
||||||
query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -25,13 +25,13 @@ class MatchQueryParser : public QueryParser
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MatchQueryParser(uint32_t a, Json::Value& v);
|
MatchQueryParser(uint32_t a, Json::Value& v);
|
||||||
~MatchQueryParser();
|
~MatchQueryParser();
|
||||||
int ParseContent(QueryParserRes* query_parser_res);
|
int ParseContent(QueryParserRes* query_parser_res);
|
||||||
int ParseContent(QueryParserRes* query_parser_res, uint32_t type);
|
int ParseContent(QueryParserRes* query_parser_res, uint32_t type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t appid;
|
uint32_t appid;
|
||||||
Json::Value value;
|
Json::Value value;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -62,15 +62,15 @@ public:
|
|||||||
private:
|
private:
|
||||||
uint32_t m_has_gis;
|
uint32_t m_has_gis;
|
||||||
string latitude;
|
string latitude;
|
||||||
string longitude;
|
string longitude;
|
||||||
double distance;
|
double distance;
|
||||||
string err_msg;
|
string err_msg;
|
||||||
map<uint32_t, vector<FieldInfo> > field_keys_map;
|
map<uint32_t, vector<FieldInfo> > field_keys_map;
|
||||||
map<uint32_t, vector<FieldInfo> > or_field_keys_map;
|
map<uint32_t, vector<FieldInfo> > or_field_keys_map;
|
||||||
map<uint32_t, vector<FieldInfo> > invert_field_keys_map;
|
map<uint32_t, vector<FieldInfo> > invert_field_keys_map;
|
||||||
vector<ExtraFilterKey> extra_filter_keys;
|
vector<ExtraFilterKey> extra_filter_keys;
|
||||||
vector<ExtraFilterKey> extra_filter_and_keys;
|
vector<ExtraFilterKey> extra_filter_and_keys;
|
||||||
vector<ExtraFilterKey> extra_filter_invert_keys;
|
vector<ExtraFilterKey> extra_filter_invert_keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QueryParser{
|
class QueryParser{
|
||||||
|
@ -22,74 +22,74 @@ int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
|
|
||||||
int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
|
int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
|
||||||
vector<FieldInfo> fieldInfos;
|
vector<FieldInfo> fieldInfos;
|
||||||
Json::Value::Members member = value.getMemberNames();
|
Json::Value::Members member = value.getMemberNames();
|
||||||
Json::Value::Members::iterator iter = member.begin();
|
Json::Value::Members::iterator iter = member.begin();
|
||||||
if(iter != member.end()){ // 一个range下只对应一个字段
|
if(iter != member.end()){ // 一个range下只对应一个字段
|
||||||
string fieldname = *iter;
|
string fieldname = *iter;
|
||||||
uint32_t segment_tag = 0;
|
uint32_t segment_tag = 0;
|
||||||
FieldInfo fieldInfo;
|
FieldInfo fieldInfo;
|
||||||
DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
||||||
Json::Value field_value = value[fieldname];
|
Json::Value field_value = value[fieldname];
|
||||||
if(field_value.isObject()){
|
if(field_value.isObject()){
|
||||||
FieldInfo info;
|
FieldInfo info;
|
||||||
Json::Value start;
|
Json::Value start;
|
||||||
Json::Value end;
|
Json::Value end;
|
||||||
if(field_value.isMember(GTE)){
|
if(field_value.isMember(GTE)){
|
||||||
start = field_value[GTE];
|
start = field_value[GTE];
|
||||||
if(field_value.isMember(LTE)){
|
if(field_value.isMember(LTE)){
|
||||||
end = field_value[LTE];
|
end = field_value[LTE];
|
||||||
info.range_type = RANGE_GELE;
|
info.range_type = RANGE_GELE;
|
||||||
} else if(field_value.isMember(LT)){
|
} else if(field_value.isMember(LT)){
|
||||||
end = field_value[LT];
|
end = field_value[LT];
|
||||||
info.range_type = RANGE_GELT;
|
info.range_type = RANGE_GELT;
|
||||||
} else {
|
} else {
|
||||||
info.range_type = RANGE_GE;
|
info.range_type = RANGE_GE;
|
||||||
}
|
}
|
||||||
} else if(field_value.isMember(GT)){
|
} else if(field_value.isMember(GT)){
|
||||||
start = field_value[GT];
|
start = field_value[GT];
|
||||||
if(field_value.isMember(LTE)){
|
if(field_value.isMember(LTE)){
|
||||||
end = field_value[LTE];
|
end = field_value[LTE];
|
||||||
info.range_type = RANGE_GTLE;
|
info.range_type = RANGE_GTLE;
|
||||||
} else if(field_value.isMember(LT)){
|
} else if(field_value.isMember(LT)){
|
||||||
end = field_value[LT];
|
end = field_value[LT];
|
||||||
info.range_type = RANGE_GTLT;
|
info.range_type = RANGE_GTLT;
|
||||||
} else {
|
} else {
|
||||||
info.range_type = RANGE_GT;
|
info.range_type = RANGE_GT;
|
||||||
}
|
}
|
||||||
} else if(field_value.isMember(LTE)){
|
} else if(field_value.isMember(LTE)){
|
||||||
end = field_value[LTE];
|
end = field_value[LTE];
|
||||||
info.range_type = RANGE_LE;
|
info.range_type = RANGE_LE;
|
||||||
} else if(field_value.isMember(LT)){
|
} else if(field_value.isMember(LT)){
|
||||||
end = field_value[LT];
|
end = field_value[LT];
|
||||||
info.range_type = RANGE_LT;
|
info.range_type = RANGE_LT;
|
||||||
}
|
}
|
||||||
if(!start.isInt() && !start.isNull()){
|
if(!start.isInt() && !start.isNull()){
|
||||||
log_error("range query only support integer");
|
log_error("range query only support integer");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
if(!end.isInt() && !end.isNull()){
|
if(!end.isInt() && !end.isNull()){
|
||||||
log_error("range query only support integer");
|
log_error("range query only support integer");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
if(start.isInt() || end.isInt()){
|
if(start.isInt() || end.isInt()){
|
||||||
fieldInfo.start = start.isInt() ? start.asInt() : 0;
|
fieldInfo.start = start.isInt() ? start.asInt() : 0;
|
||||||
fieldInfo.end = end.isInt() ? end.asInt() : 0;
|
fieldInfo.end = end.isInt() ? end.asInt() : 0;
|
||||||
fieldInfo.range_type = info.range_type;
|
fieldInfo.range_type = info.range_type;
|
||||||
fieldInfos.push_back(fieldInfo);
|
fieldInfos.push_back(fieldInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(fieldInfos.size() != 0){
|
if(fieldInfos.size() != 0){
|
||||||
if(type == ORKEY){
|
if(type == ORKEY){
|
||||||
query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
} else if(type == ANDKEY){
|
} else if(type == ANDKEY){
|
||||||
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
} else if(type == INVERTKEY){
|
} else if(type == INVERTKEY){
|
||||||
query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_error("RangeQueryParser error, value is null");
|
log_error("RangeQueryParser error, value is null");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -25,13 +25,13 @@ class RangeQueryParser : public QueryParser
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RangeQueryParser(uint32_t a, Json::Value& v);
|
RangeQueryParser(uint32_t a, Json::Value& v);
|
||||||
~RangeQueryParser();
|
~RangeQueryParser();
|
||||||
int ParseContent(QueryParserRes* query_parser_res);
|
int ParseContent(QueryParserRes* query_parser_res);
|
||||||
int ParseContent(QueryParserRes* query_parser_res, uint32_t type);
|
int ParseContent(QueryParserRes* query_parser_res, uint32_t type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t appid;
|
uint32_t appid;
|
||||||
Json::Value value;
|
Json::Value value;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -18,47 +18,47 @@ int TermQueryParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
|
|
||||||
int TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
|
int TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
|
||||||
vector<FieldInfo> fieldInfos;
|
vector<FieldInfo> fieldInfos;
|
||||||
Json::Value::Members member = value.getMemberNames();
|
Json::Value::Members member = value.getMemberNames();
|
||||||
Json::Value::Members::iterator iter = member.begin();
|
Json::Value::Members::iterator iter = member.begin();
|
||||||
string fieldname;
|
string fieldname;
|
||||||
string field_value;
|
string field_value;
|
||||||
Json::Value json_value;
|
Json::Value json_value;
|
||||||
if(iter != member.end()){ // 一个term下只对应一个字段
|
if(iter != member.end()){ // 一个term下只对应一个字段
|
||||||
fieldname = *iter;
|
fieldname = *iter;
|
||||||
json_value = value[fieldname];
|
json_value = value[fieldname];
|
||||||
field_value = json_value.asString();
|
field_value = json_value.asString();
|
||||||
} else {
|
} else {
|
||||||
log_error("TermQueryParser error, value is null");
|
log_error("TermQueryParser error, value is null");
|
||||||
return -RT_PARSE_CONTENT_ERROR;
|
return -RT_PARSE_CONTENT_ERROR;
|
||||||
}
|
}
|
||||||
uint32_t segment_tag = 0;
|
uint32_t segment_tag = 0;
|
||||||
FieldInfo fieldInfo;
|
FieldInfo fieldInfo;
|
||||||
uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo);
|
||||||
if(field != 0 && fieldInfo.index_tag == 0){
|
if(field != 0 && fieldInfo.index_tag == 0){
|
||||||
ExtraFilterKey extra_filter_key;
|
ExtraFilterKey extra_filter_key;
|
||||||
extra_filter_key.field_name = fieldname;
|
extra_filter_key.field_name = fieldname;
|
||||||
extra_filter_key.field_value = field_value;
|
extra_filter_key.field_value = field_value;
|
||||||
extra_filter_key.field_type = fieldInfo.field_type;
|
extra_filter_key.field_type = fieldInfo.field_type;
|
||||||
if(type == ORKEY){
|
if(type == ORKEY){
|
||||||
query_parser_res->ExtraFilterKeys().push_back(extra_filter_key);
|
query_parser_res->ExtraFilterKeys().push_back(extra_filter_key);
|
||||||
} else if (type == ANDKEY) {
|
} else if (type == ANDKEY) {
|
||||||
query_parser_res->ExtraFilterAndKeys().push_back(extra_filter_key);
|
query_parser_res->ExtraFilterAndKeys().push_back(extra_filter_key);
|
||||||
} else if (type == INVERTKEY) {
|
} else if (type == INVERTKEY) {
|
||||||
query_parser_res->ExtraFilterInvertKeys().push_back(extra_filter_key);
|
query_parser_res->ExtraFilterInvertKeys().push_back(extra_filter_key);
|
||||||
}
|
}
|
||||||
} else if (field != 0)
|
} else if (field != 0)
|
||||||
{
|
{
|
||||||
fieldInfo.word = field_value;
|
fieldInfo.word = field_value;
|
||||||
fieldInfos.push_back(fieldInfo);
|
fieldInfos.push_back(fieldInfo);
|
||||||
}
|
}
|
||||||
if(fieldInfos.size() != 0){
|
if(fieldInfos.size() != 0){
|
||||||
if(type == ORKEY){
|
if(type == ORKEY){
|
||||||
query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
} else if(type == ANDKEY) {
|
} else if(type == ANDKEY) {
|
||||||
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
} else if(type == INVERTKEY){
|
} else if(type == INVERTKEY){
|
||||||
query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -25,13 +25,13 @@ class TermQueryParser : public QueryParser
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TermQueryParser(uint32_t a, Json::Value& v);
|
TermQueryParser(uint32_t a, Json::Value& v);
|
||||||
~TermQueryParser();
|
~TermQueryParser();
|
||||||
int ParseContent(QueryParserRes* query_parser_res);
|
int ParseContent(QueryParserRes* query_parser_res);
|
||||||
int ParseContent(QueryParserRes* query_parser_res, uint32_t type);
|
int ParseContent(QueryParserRes* query_parser_res, uint32_t type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t appid;
|
uint32_t appid;
|
||||||
Json::Value value;
|
Json::Value value;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user