From fb6a8f3d02fa890a9ebf8912fb0b61a4fef30304 Mon Sep 17 00:00:00 2001 From: shzhulin3 Date: Thu, 29 Apr 2021 17:44:42 +0800 Subject: [PATCH] convert tab to spaces --- .../index_read/query/bool_query_parser.cc | 180 +++++++++--------- .../index_read/query/bool_query_parser.h | 20 +- .../index_read/query/geo_distance_parser.cc | 94 ++++----- .../index_read/query/geo_distance_parser.h | 6 +- .../index_read/query/match_query_parser.cc | 88 ++++----- .../index_read/query/match_query_parser.h | 6 +- .../index_read/query/query_parser.h | 10 +- .../index_read/query/range_query_parser.cc | 132 ++++++------- .../index_read/query/range_query_parser.h | 6 +- .../index_read/query/term_query_parser.cc | 76 ++++---- .../index_read/query/term_query_parser.h | 6 +- 11 files changed, 312 insertions(+), 312 deletions(-) diff --git a/src/search_local/index_read/query/bool_query_parser.cc b/src/search_local/index_read/query/bool_query_parser.cc index 2e4533b..e235921 100644 --- a/src/search_local/index_read/query/bool_query_parser.cc +++ b/src/search_local/index_read/query/bool_query_parser.cc @@ -22,100 +22,100 @@ BoolQueryParser::BoolQueryParser(uint32_t a, Json::Value& v) } BoolQueryParser::~BoolQueryParser(){ - if(NULL != range_query_parser){ - delete range_query_parser; - } - if(NULL != term_query_parser){ - delete term_query_parser; - } - if(NULL != match_query_parser){ - delete match_query_parser; - } - if(NULL != geo_query_parser){ - delete geo_query_parser; - } + if(NULL != range_query_parser){ + delete range_query_parser; + } + if(NULL != term_query_parser){ + delete term_query_parser; + } + if(NULL != match_query_parser){ + delete match_query_parser; + } + if(NULL != geo_query_parser){ + delete geo_query_parser; + } } int BoolQueryParser::DoJobByType(Json::Value& value, uint32_t type, QueryParserRes* query_parser_res){ - if(value.isMember(TERM)){ - term_query_parser = new TermQueryParser(appid, value[TERM]); - return term_query_parser->ParseContent(query_parser_res, type); - } else if(value.isMember(MATCH)){ - match_query_parser = new MatchQueryParser(appid, value[MATCH]); - return match_query_parser->ParseContent(query_parser_res, type); - } else if(value.isMember(RANGE)){ - range_query_parser = new RangeQueryParser(appid, value[RANGE]); - return range_query_parser->ParseContent(query_parser_res, type); - } else if(value.isMember(GEODISTANCE)){ - geo_query_parser = new GeoDistanceParser(appid, value[GEODISTANCE]); - return geo_query_parser->ParseContent(query_parser_res); - } else { - string err_msg = "BoolQueryParser only support term/match/range/geo_distance!"; - log_error(err_msg.c_str()); - query_parser_res->ErrMsg() = err_msg; - return -RT_PARSE_CONTENT_ERROR; - } - return 0; + if(value.isMember(TERM)){ + term_query_parser = new TermQueryParser(appid, value[TERM]); + return term_query_parser->ParseContent(query_parser_res, type); + } else if(value.isMember(MATCH)){ + match_query_parser = new MatchQueryParser(appid, value[MATCH]); + return match_query_parser->ParseContent(query_parser_res, type); + } else if(value.isMember(RANGE)){ + range_query_parser = new RangeQueryParser(appid, value[RANGE]); + return range_query_parser->ParseContent(query_parser_res, type); + } else if(value.isMember(GEODISTANCE)){ + geo_query_parser = new GeoDistanceParser(appid, value[GEODISTANCE]); + return geo_query_parser->ParseContent(query_parser_res); + } else { + string err_msg = "BoolQueryParser only support term/match/range/geo_distance!"; + log_error(err_msg.c_str()); + query_parser_res->ErrMsg() = err_msg; + return -RT_PARSE_CONTENT_ERROR; + } + return 0; } int BoolQueryParser::ParseContent(QueryParserRes* query_parser_res){ - int ret = 0; - if(value.isMember(MUST)){ - int type = ANDKEY; - Json::Value must = value[MUST]; - if(must.isArray()){ - for(int i = 0; i < (int)must.size(); i++){ - ret = DoJobByType(must[i], type, query_parser_res); - if(ret != 0){ - log_error("DoJobByType error!"); - return -RT_PARSE_CONTENT_ERROR; - } - } - } else if (must.isObject()){ - ret = DoJobByType(must, type, query_parser_res); - if(ret != 0){ - log_error("DoJobByType error!"); - return -RT_PARSE_CONTENT_ERROR; - } - } - } - if (value.isMember(SHOULD)){ - int type = ORKEY; - Json::Value should = value[SHOULD]; - if(should.isArray()){ - for(int i = 0; i < (int)should.size(); i++){ - ret = DoJobByType(should[i], type, query_parser_res); - if(ret != 0){ - log_error("DoJobByType error!"); - return -RT_PARSE_CONTENT_ERROR; - } - } - } else if (should.isObject()){ - ret = DoJobByType(should, type, query_parser_res); - if(ret != 0){ - log_error("DoJobByType error!"); - return -RT_PARSE_CONTENT_ERROR; - } - } - } - if (value.isMember(MUST_NOT)){ - int type = INVERTKEY; - Json::Value must_not = value[MUST_NOT]; - if(must_not.isArray()){ - for(int i = 0; i < (int)must_not.size(); i++){ - ret = DoJobByType(must_not[i], type, query_parser_res); - if(ret != 0){ - log_error("DoJobByType error!"); - return -RT_PARSE_CONTENT_ERROR; - } - } - } else if (must_not.isObject()) { - ret = DoJobByType(must_not, type, query_parser_res); - if(ret != 0){ - log_error("DoJobByType error!"); - return -RT_PARSE_CONTENT_ERROR; - } - } - } - return 0; + int ret = 0; + if(value.isMember(MUST)){ + int type = ANDKEY; + Json::Value must = value[MUST]; + if(must.isArray()){ + for(int i = 0; i < (int)must.size(); i++){ + ret = DoJobByType(must[i], type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } + } + } else if (must.isObject()){ + ret = DoJobByType(must, type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } + } + } + if (value.isMember(SHOULD)){ + int type = ORKEY; + Json::Value should = value[SHOULD]; + if(should.isArray()){ + for(int i = 0; i < (int)should.size(); i++){ + ret = DoJobByType(should[i], type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } + } + } else if (should.isObject()){ + ret = DoJobByType(should, type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } + } + } + if (value.isMember(MUST_NOT)){ + int type = INVERTKEY; + Json::Value must_not = value[MUST_NOT]; + if(must_not.isArray()){ + for(int i = 0; i < (int)must_not.size(); i++){ + ret = DoJobByType(must_not[i], type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } + } + } else if (must_not.isObject()) { + ret = DoJobByType(must_not, type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } + } + } + return 0; } \ No newline at end of file diff --git a/src/search_local/index_read/query/bool_query_parser.h b/src/search_local/index_read/query/bool_query_parser.h index f6d61d2..33031fa 100644 --- a/src/search_local/index_read/query/bool_query_parser.h +++ b/src/search_local/index_read/query/bool_query_parser.h @@ -28,21 +28,21 @@ class GeoDistanceParser; class BoolQueryParser : public QueryParser { public: - BoolQueryParser(uint32_t a, Json::Value& v); - ~BoolQueryParser(); + BoolQueryParser(uint32_t a, Json::Value& v); + ~BoolQueryParser(); - int ParseContent(QueryParserRes* query_parser_res); + int ParseContent(QueryParserRes* query_parser_res); 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: - uint32_t appid; - Json::Value value; - RangeQueryParser* range_query_parser; - TermQueryParser* term_query_parser; - MatchQueryParser* match_query_parser; - GeoDistanceParser* geo_query_parser; + uint32_t appid; + Json::Value value; + RangeQueryParser* range_query_parser; + TermQueryParser* term_query_parser; + MatchQueryParser* match_query_parser; + GeoDistanceParser* geo_query_parser; }; #endif \ No newline at end of file diff --git a/src/search_local/index_read/query/geo_distance_parser.cc b/src/search_local/index_read/query/geo_distance_parser.cc index 2835e71..88edbf4 100644 --- a/src/search_local/index_read/query/geo_distance_parser.cc +++ b/src/search_local/index_read/query/geo_distance_parser.cc @@ -18,28 +18,28 @@ GeoDistanceParser::~GeoDistanceParser(){ vector splitDouble(const string& src, string separate_character) { - vector strs; + vector strs; - //分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符 - int separate_characterLen = separate_character.size(); - int lastPosition = 0, index = -1; - string str; - double pos = 0; - while (-1 != (index = src.find(separate_character, lastPosition))) - { - if (src.substr(lastPosition, index - lastPosition) != " ") { - str = src.substr(lastPosition, index - lastPosition); - pos = atof(str.c_str()); - strs.push_back(pos); - } - lastPosition = index + separate_characterLen; - } - string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容 - if (!lastString.empty() && lastString != " "){ - pos = atof(lastString.c_str()); - strs.push_back(pos);//如果最后一个分隔符后还有内容就入队 + //分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符 + int separate_characterLen = separate_character.size(); + int lastPosition = 0, index = -1; + string str; + double pos = 0; + while (-1 != (index = src.find(separate_character, lastPosition))) + { + if (src.substr(lastPosition, index - lastPosition) != " ") { + str = src.substr(lastPosition, index - lastPosition); + pos = atof(str.c_str()); + strs.push_back(pos); + } + lastPosition = index + separate_characterLen; } - 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){ @@ -51,9 +51,9 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ vector fieldInfos; double distance = 0; string fieldname; - Json::Value::Members member = value.getMemberNames(); - Json::Value::Members::iterator iter = member.begin(); - for(; iter != member.end(); iter++){ + Json::Value::Members member = value.getMemberNames(); + Json::Value::Members::iterator iter = member.begin(); + for(; iter != member.end(); iter++){ Json::Value geo_value = value[*iter]; if(DISTANCE == *iter){ if(geo_value.isString()){ @@ -72,7 +72,7 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ geo.lon = res[1]; } else { SetErrMsg(query_parser_res, "GeoDistanceParser format error."); - return -RT_PARSE_CONTENT_ERROR; + return -RT_PARSE_CONTENT_ERROR; } } else if (geo_value.isArray()){ if(geo_value.size() >= 2){ @@ -84,24 +84,24 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ } } else { SetErrMsg(query_parser_res, "GeoDistanceParser format error."); - return -RT_PARSE_CONTENT_ERROR; + return -RT_PARSE_CONTENT_ERROR; } } else if (geo_value.isObject()){ if(geo_value.isMember("lat") && geo_value["lat"].isDouble()){ geo.lat = geo_value["lat"].asDouble(); } else { 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()){ geo.lon = geo_value["lon"].asDouble(); } else { SetErrMsg(query_parser_res, "GeoDistanceParser lon format error."); - return -RT_PARSE_CONTENT_ERROR; + return -RT_PARSE_CONTENT_ERROR; } } else { 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 gisCode = GetArroundGeoHash(geo, distance, GEO_PRECISION); if(gisCode.size() > 0){ - vector fieldInfos; - uint32_t segment_tag = 0; - FieldInfo fieldInfo; - uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); - if (field != 0 && segment_tag == 0) { - query_parser_res->HasGis() = 1; - for (size_t index = 0; index < gisCode.size(); index++) { - FieldInfo info; - info.field = fieldInfo.field; - info.field_type = fieldInfo.field_type; - info.segment_tag = fieldInfo.segment_tag; - info.word = gisCode[index]; - fieldInfos.push_back(info); - } - } - if (fieldInfos.size() != 0) { - query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } + vector fieldInfos; + uint32_t segment_tag = 0; + FieldInfo fieldInfo; + uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); + if (field != 0 && segment_tag == 0) { + query_parser_res->HasGis() = 1; + for (size_t index = 0; index < gisCode.size(); index++) { + FieldInfo info; + info.field = fieldInfo.field; + info.field_type = fieldInfo.field_type; + info.segment_tag = fieldInfo.segment_tag; + info.word = gisCode[index]; + fieldInfos.push_back(info); + } + } + if (fieldInfos.size() != 0) { + query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); + } stringstream sslat; stringstream sslon; sslat << geo.lat; @@ -135,6 +135,6 @@ int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ sslon << geo.lon; query_parser_res->Longitude() = sslon.str(); query_parser_res->Distance() = distance; - } + } return 0; } \ No newline at end of file diff --git a/src/search_local/index_read/query/geo_distance_parser.h b/src/search_local/index_read/query/geo_distance_parser.h index 24a1690..b9411de 100644 --- a/src/search_local/index_read/query/geo_distance_parser.h +++ b/src/search_local/index_read/query/geo_distance_parser.h @@ -26,12 +26,12 @@ class GeoDistanceParser : public QueryParser { public: GeoDistanceParser(uint32_t a, Json::Value& v); - ~GeoDistanceParser(); + ~GeoDistanceParser(); int ParseContent(QueryParserRes* query_parser_res); private: - uint32_t appid; - Json::Value value; + uint32_t appid; + Json::Value value; GeoPoint geo; double distance; }; diff --git a/src/search_local/index_read/query/match_query_parser.cc b/src/search_local/index_read/query/match_query_parser.cc index 1670234..f41c264 100644 --- a/src/search_local/index_read/query/match_query_parser.cc +++ b/src/search_local/index_read/query/match_query_parser.cc @@ -18,49 +18,49 @@ int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res){ int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){ vector fieldInfos; - Json::Value::Members member = value.getMemberNames(); - Json::Value::Members::iterator iter = member.begin(); - string fieldname; - Json::Value field_value; - if(iter != member.end()){ // 一个match下只对应一个字段 - fieldname = *iter; - field_value = value[fieldname]; - } else { - log_error("TermQueryParser error, value is null"); - return -RT_PARSE_CONTENT_ERROR; - } - uint32_t segment_tag = 0; - FieldInfo fieldInfo; - uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); - if (field != 0 && segment_tag == 1) - { - string split_data = SplitManager::Instance()->split(field_value.asString(), appid); - log_debug("split_data: %s", split_data.c_str()); - vector split_datas = splitEx(split_data, "|"); - for(size_t index = 0; index < split_datas.size(); index++) - { - FieldInfo info; - info.field = fieldInfo.field; - info.field_type = fieldInfo.field_type; - info.word = split_datas[index]; - info.segment_tag = fieldInfo.segment_tag; - fieldInfos.push_back(info); - } - } - else if (field != 0) - { - fieldInfo.word = field_value.asString(); - fieldInfos.push_back(fieldInfo); - } + Json::Value::Members member = value.getMemberNames(); + Json::Value::Members::iterator iter = member.begin(); + string fieldname; + Json::Value field_value; + if(iter != member.end()){ // 一个match下只对应一个字段 + fieldname = *iter; + field_value = value[fieldname]; + } else { + log_error("TermQueryParser error, value is null"); + return -RT_PARSE_CONTENT_ERROR; + } + uint32_t segment_tag = 0; + FieldInfo fieldInfo; + uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); + if (field != 0 && segment_tag == 1) + { + string split_data = SplitManager::Instance()->split(field_value.asString(), appid); + log_debug("split_data: %s", split_data.c_str()); + vector split_datas = splitEx(split_data, "|"); + for(size_t index = 0; index < split_datas.size(); index++) + { + FieldInfo info; + info.field = fieldInfo.field; + info.field_type = fieldInfo.field_type; + info.word = split_datas[index]; + info.segment_tag = fieldInfo.segment_tag; + fieldInfos.push_back(info); + } + } + else if (field != 0) + { + fieldInfo.word = field_value.asString(); + fieldInfos.push_back(fieldInfo); + } - if(fieldInfos.size() != 0){ - if(type == ORKEY){ - query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } else if(type == ANDKEY){ - query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } else if(type == INVERTKEY){ - query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } - } - return 0; + if(fieldInfos.size() != 0){ + if(type == ORKEY){ + query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); + } else if(type == ANDKEY){ + query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); + } else if(type == INVERTKEY){ + query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); + } + } + return 0; } \ No newline at end of file diff --git a/src/search_local/index_read/query/match_query_parser.h b/src/search_local/index_read/query/match_query_parser.h index 38345d1..89d922e 100644 --- a/src/search_local/index_read/query/match_query_parser.h +++ b/src/search_local/index_read/query/match_query_parser.h @@ -25,13 +25,13 @@ class MatchQueryParser : public QueryParser { public: MatchQueryParser(uint32_t a, Json::Value& v); - ~MatchQueryParser(); + ~MatchQueryParser(); int ParseContent(QueryParserRes* query_parser_res); int ParseContent(QueryParserRes* query_parser_res, uint32_t type); private: - uint32_t appid; - Json::Value value; + uint32_t appid; + Json::Value value; }; #endif \ No newline at end of file diff --git a/src/search_local/index_read/query/query_parser.h b/src/search_local/index_read/query/query_parser.h index d3a1aa6..0dd4be4 100644 --- a/src/search_local/index_read/query/query_parser.h +++ b/src/search_local/index_read/query/query_parser.h @@ -62,15 +62,15 @@ public: private: uint32_t m_has_gis; string latitude; - string longitude; - double distance; + string longitude; + double distance; string err_msg; map > field_keys_map; - map > or_field_keys_map; + map > or_field_keys_map; map > invert_field_keys_map; vector extra_filter_keys; - vector extra_filter_and_keys; - vector extra_filter_invert_keys; + vector extra_filter_and_keys; + vector extra_filter_invert_keys; }; class QueryParser{ diff --git a/src/search_local/index_read/query/range_query_parser.cc b/src/search_local/index_read/query/range_query_parser.cc index fe2cb4a..f4d4ad9 100644 --- a/src/search_local/index_read/query/range_query_parser.cc +++ b/src/search_local/index_read/query/range_query_parser.cc @@ -22,74 +22,74 @@ int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res){ int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){ vector fieldInfos; - Json::Value::Members member = value.getMemberNames(); - Json::Value::Members::iterator iter = member.begin(); - if(iter != member.end()){ // 一个range下只对应一个字段 - string fieldname = *iter; - uint32_t segment_tag = 0; - FieldInfo fieldInfo; - DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); - Json::Value field_value = value[fieldname]; - if(field_value.isObject()){ - FieldInfo info; - Json::Value start; - Json::Value end; - if(field_value.isMember(GTE)){ - start = field_value[GTE]; - if(field_value.isMember(LTE)){ - end = field_value[LTE]; - info.range_type = RANGE_GELE; - } else if(field_value.isMember(LT)){ - end = field_value[LT]; - info.range_type = RANGE_GELT; - } else { - info.range_type = RANGE_GE; - } - } else if(field_value.isMember(GT)){ - start = field_value[GT]; - if(field_value.isMember(LTE)){ - end = field_value[LTE]; - info.range_type = RANGE_GTLE; - } else if(field_value.isMember(LT)){ - end = field_value[LT]; - info.range_type = RANGE_GTLT; - } else { - info.range_type = RANGE_GT; - } - } else if(field_value.isMember(LTE)){ - end = field_value[LTE]; - info.range_type = RANGE_LE; - } else if(field_value.isMember(LT)){ - end = field_value[LT]; - info.range_type = RANGE_LT; - } - if(!start.isInt() && !start.isNull()){ - log_error("range query only support integer"); - return -RT_PARSE_CONTENT_ERROR; - } - if(!end.isInt() && !end.isNull()){ - log_error("range query only support integer"); - return -RT_PARSE_CONTENT_ERROR; - } - if(start.isInt() || end.isInt()){ - fieldInfo.start = start.isInt() ? start.asInt() : 0; - fieldInfo.end = end.isInt() ? end.asInt() : 0; - fieldInfo.range_type = info.range_type; - fieldInfos.push_back(fieldInfo); - } - } - if(fieldInfos.size() != 0){ + Json::Value::Members member = value.getMemberNames(); + Json::Value::Members::iterator iter = member.begin(); + if(iter != member.end()){ // 一个range下只对应一个字段 + string fieldname = *iter; + uint32_t segment_tag = 0; + FieldInfo fieldInfo; + DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); + Json::Value field_value = value[fieldname]; + if(field_value.isObject()){ + FieldInfo info; + Json::Value start; + Json::Value end; + if(field_value.isMember(GTE)){ + start = field_value[GTE]; + if(field_value.isMember(LTE)){ + end = field_value[LTE]; + info.range_type = RANGE_GELE; + } else if(field_value.isMember(LT)){ + end = field_value[LT]; + info.range_type = RANGE_GELT; + } else { + info.range_type = RANGE_GE; + } + } else if(field_value.isMember(GT)){ + start = field_value[GT]; + if(field_value.isMember(LTE)){ + end = field_value[LTE]; + info.range_type = RANGE_GTLE; + } else if(field_value.isMember(LT)){ + end = field_value[LT]; + info.range_type = RANGE_GTLT; + } else { + info.range_type = RANGE_GT; + } + } else if(field_value.isMember(LTE)){ + end = field_value[LTE]; + info.range_type = RANGE_LE; + } else if(field_value.isMember(LT)){ + end = field_value[LT]; + info.range_type = RANGE_LT; + } + if(!start.isInt() && !start.isNull()){ + log_error("range query only support integer"); + return -RT_PARSE_CONTENT_ERROR; + } + if(!end.isInt() && !end.isNull()){ + log_error("range query only support integer"); + return -RT_PARSE_CONTENT_ERROR; + } + if(start.isInt() || end.isInt()){ + fieldInfo.start = start.isInt() ? start.asInt() : 0; + fieldInfo.end = end.isInt() ? end.asInt() : 0; + fieldInfo.range_type = info.range_type; + fieldInfos.push_back(fieldInfo); + } + } + if(fieldInfos.size() != 0){ if(type == ORKEY){ query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); } 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){ - query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } - } - } else { - log_error("RangeQueryParser error, value is null"); - return -RT_PARSE_CONTENT_ERROR; - } - return 0; + query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); + } + } + } else { + log_error("RangeQueryParser error, value is null"); + return -RT_PARSE_CONTENT_ERROR; + } + return 0; } \ No newline at end of file diff --git a/src/search_local/index_read/query/range_query_parser.h b/src/search_local/index_read/query/range_query_parser.h index c2ed204..2b34a63 100644 --- a/src/search_local/index_read/query/range_query_parser.h +++ b/src/search_local/index_read/query/range_query_parser.h @@ -25,13 +25,13 @@ class RangeQueryParser : public QueryParser { public: RangeQueryParser(uint32_t a, Json::Value& v); - ~RangeQueryParser(); + ~RangeQueryParser(); int ParseContent(QueryParserRes* query_parser_res); int ParseContent(QueryParserRes* query_parser_res, uint32_t type); private: - uint32_t appid; - Json::Value value; + uint32_t appid; + Json::Value value; }; #endif \ No newline at end of file diff --git a/src/search_local/index_read/query/term_query_parser.cc b/src/search_local/index_read/query/term_query_parser.cc index 0f1607e..3148f20 100644 --- a/src/search_local/index_read/query/term_query_parser.cc +++ b/src/search_local/index_read/query/term_query_parser.cc @@ -18,47 +18,47 @@ int TermQueryParser::ParseContent(QueryParserRes* query_parser_res){ int TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){ vector fieldInfos; - Json::Value::Members member = value.getMemberNames(); - Json::Value::Members::iterator iter = member.begin(); - string fieldname; - string field_value; - Json::Value json_value; - if(iter != member.end()){ // 一个term下只对应一个字段 - fieldname = *iter; - json_value = value[fieldname]; - field_value = json_value.asString(); - } else { - log_error("TermQueryParser error, value is null"); - return -RT_PARSE_CONTENT_ERROR; - } - uint32_t segment_tag = 0; - FieldInfo fieldInfo; - uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); - if(field != 0 && fieldInfo.index_tag == 0){ - ExtraFilterKey extra_filter_key; - extra_filter_key.field_name = fieldname; - extra_filter_key.field_value = field_value; - extra_filter_key.field_type = fieldInfo.field_type; - if(type == ORKEY){ - query_parser_res->ExtraFilterKeys().push_back(extra_filter_key); - } else if (type == ANDKEY) { - query_parser_res->ExtraFilterAndKeys().push_back(extra_filter_key); - } else if (type == INVERTKEY) { - query_parser_res->ExtraFilterInvertKeys().push_back(extra_filter_key); - } - } else if (field != 0) - { - fieldInfo.word = field_value; - fieldInfos.push_back(fieldInfo); - } - if(fieldInfos.size() != 0){ + Json::Value::Members member = value.getMemberNames(); + Json::Value::Members::iterator iter = member.begin(); + string fieldname; + string field_value; + Json::Value json_value; + if(iter != member.end()){ // 一个term下只对应一个字段 + fieldname = *iter; + json_value = value[fieldname]; + field_value = json_value.asString(); + } else { + log_error("TermQueryParser error, value is null"); + return -RT_PARSE_CONTENT_ERROR; + } + uint32_t segment_tag = 0; + FieldInfo fieldInfo; + uint32_t field = DBManager::Instance()->GetWordField(segment_tag, appid, fieldname, fieldInfo); + if(field != 0 && fieldInfo.index_tag == 0){ + ExtraFilterKey extra_filter_key; + extra_filter_key.field_name = fieldname; + extra_filter_key.field_value = field_value; + extra_filter_key.field_type = fieldInfo.field_type; + if(type == ORKEY){ + query_parser_res->ExtraFilterKeys().push_back(extra_filter_key); + } else if (type == ANDKEY) { + query_parser_res->ExtraFilterAndKeys().push_back(extra_filter_key); + } else if (type == INVERTKEY) { + query_parser_res->ExtraFilterInvertKeys().push_back(extra_filter_key); + } + } else if (field != 0) + { + fieldInfo.word = field_value; + fieldInfos.push_back(fieldInfo); + } + if(fieldInfos.size() != 0){ if(type == ORKEY){ query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); } else if(type == ANDKEY) { query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); } else if(type == INVERTKEY){ - query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } - } - return 0; + query_parser_res->InvertFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); + } + } + return 0; } \ No newline at end of file diff --git a/src/search_local/index_read/query/term_query_parser.h b/src/search_local/index_read/query/term_query_parser.h index 56321b4..389e6ea 100644 --- a/src/search_local/index_read/query/term_query_parser.h +++ b/src/search_local/index_read/query/term_query_parser.h @@ -25,13 +25,13 @@ class TermQueryParser : public QueryParser { public: TermQueryParser(uint32_t a, Json::Value& v); - ~TermQueryParser(); + ~TermQueryParser(); int ParseContent(QueryParserRes* query_parser_res); int ParseContent(QueryParserRes* query_parser_res, uint32_t type); private: - uint32_t appid; - Json::Value value; + uint32_t appid; + Json::Value value; }; #endif \ No newline at end of file