From 108af1144333a1830ed4852b3595b1fa1c61b90c Mon Sep 17 00:00:00 2001 From: shzhulin3 Date: Wed, 28 Apr 2021 11:23:09 +0800 Subject: [PATCH] complete BoolQueryParser --- src/search_local/index_read/comm.h | 1 + src/search_local/index_read/component.cc | 14 +++- src/search_local/index_read/component.h | 2 +- src/search_local/index_read/process_task.cc | 5 +- src/search_local/index_read/process_task.h | 2 +- .../index_read/query/bool_query_parser.cc | 71 +++++++++++++++---- .../index_read/query/bool_query_parser.h | 4 +- .../index_read/query/geo_distance_parser.cc | 39 ++++++++-- .../index_read/query/geo_distance_parser.h | 2 +- .../index_read/query/match_query_parser.cc | 23 +++--- .../index_read/query/match_query_parser.h | 4 +- .../index_read/query/query_parser.h | 10 ++- .../index_read/query/range_query_parser.cc | 45 +++++++++--- .../index_read/query/range_query_parser.h | 4 +- .../index_read/query/term_query_parser.cc | 21 +++--- .../index_read/query/term_query_parser.h | 4 +- src/search_local/index_read/search_task.cc | 11 ++- 17 files changed, 198 insertions(+), 64 deletions(-) diff --git a/src/search_local/index_read/comm.h b/src/search_local/index_read/comm.h index b372f87..ac112b6 100644 --- a/src/search_local/index_read/comm.h +++ b/src/search_local/index_read/comm.h @@ -52,6 +52,7 @@ enum RetCode{ RT_GET_DOC_ERR, RT_ADD_DICT_ERR, RT_GET_FIELD_ERROR, + RT_PARSE_CONTENT_ERROR, }; typedef enum CMD { diff --git a/src/search_local/index_read/component.cc b/src/search_local/index_read/component.cc index 0f5d357..baa9035 100644 --- a/src/search_local/index_read/component.cc +++ b/src/search_local/index_read/component.cc @@ -218,7 +218,7 @@ void Component::InitSwitch() } } -void Component::GetQueryWord(uint32_t &m_has_gis){ +int Component::GetQueryWord(uint32_t &m_has_gis, string &err_msg){ if(m_query.isObject()){ if(m_query.isMember("bool")){ query_parser = new BoolQueryParser(m_appid, m_query["bool"]); @@ -232,7 +232,12 @@ void Component::GetQueryWord(uint32_t &m_has_gis){ query_parser = new TermQueryParser(m_appid, m_query["term"]); } query_parser_res = new QueryParserRes(); - query_parser->ParseContent(query_parser_res); + int ret = query_parser->ParseContent(query_parser_res); + if(ret != 0){ + err_msg = query_parser_res->ErrMsg(); + log_error("query_parser ParseContent error, ret: %d", ret); + return ret; + } map >::iterator field_key_map_iter = query_parser_res->FieldKeysMap().begin(); for(; field_key_map_iter != query_parser_res->FieldKeysMap().end(); field_key_map_iter++){ AddToFieldList(ANDKEY, field_key_map_iter->second); @@ -241,6 +246,10 @@ void Component::GetQueryWord(uint32_t &m_has_gis){ for(; or_key_map_iter != query_parser_res->OrFieldKeysMap().end(); or_key_map_iter++){ AddToFieldList(ORKEY, or_key_map_iter->second); } + map >::iterator invert_key_map_iter = query_parser_res->InvertFieldKeysMap().begin(); + for(; invert_key_map_iter != query_parser_res->InvertFieldKeysMap().end(); invert_key_map_iter++){ + AddToFieldList(INVERTKEY, invert_key_map_iter->second); + } m_has_gis = query_parser_res->HasGis(); if(m_has_gis){ latitude = query_parser_res->Latitude(); @@ -256,6 +265,7 @@ void Component::GetQueryWord(uint32_t &m_has_gis){ GetFieldWords(ANDKEY, m_Data_and, m_appid, m_has_gis); GetFieldWords(INVERTKEY, m_Data_invert, m_appid, m_has_gis); } + return 0; } void Component::GetFieldWords(int type, string dataStr, uint32_t appid, uint32_t &m_has_gis){ diff --git a/src/search_local/index_read/component.h b/src/search_local/index_read/component.h index 1dce2d3..2f35583 100644 --- a/src/search_local/index_read/component.h +++ b/src/search_local/index_read/component.h @@ -31,7 +31,7 @@ public: Component(); ~Component(); - void GetQueryWord(uint32_t &m_has_gis); + int GetQueryWord(uint32_t &m_has_gis, string &err_msg); const vector >& Keys(); const vector >& AndKeys(); const vector >& InvertKeys(); diff --git a/src/search_local/index_read/process_task.cc b/src/search_local/index_read/process_task.cc index ae94505..ac17fdb 100644 --- a/src/search_local/index_read/process_task.cc +++ b/src/search_local/index_read/process_task.cc @@ -39,9 +39,12 @@ ProcessTask::~ProcessTask() } -string ProcessTask::GenReplyStr(RSPCODE code) { +string ProcessTask::GenReplyStr(RSPCODE code, string err_msg) { Json::Value m_ReplyPacket; m_ReplyPacket["code"] = code; + if(err_msg != ""){ + m_ReplyPacket["message"] = err_msg; + } Json::StyledWriter _sw; string resultStr = _sw.write(m_ReplyPacket); return resultStr; diff --git a/src/search_local/index_read/process_task.h b/src/search_local/index_read/process_task.h index 1e257d7..7e87236 100644 --- a/src/search_local/index_read/process_task.h +++ b/src/search_local/index_read/process_task.h @@ -37,7 +37,7 @@ public: ProcessTask(); virtual ~ProcessTask(); virtual int Process(CTaskRequest *request); - string GenReplyStr(RSPCODE code); + string GenReplyStr(RSPCODE code, string err_msg = ""); }; #endif 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 ec8b508..a28c761 100644 --- a/src/search_local/index_read/query/bool_query_parser.cc +++ b/src/search_local/index_read/query/bool_query_parser.cc @@ -9,11 +9,17 @@ const char* const NAME ="bool"; const char* const MUST ="must"; const char* const SHOULD ="should"; +const char* const MUST_NOT ="must_not"; const char* const TERM ="term"; const char* const MATCH ="match"; const char* const RANGE ="range"; const char* const GEODISTANCE ="geo_distance"; +void SetErrMsg(QueryParserRes* query_parser_res, string err_msg){ + log_error(err_msg.c_str()); + query_parser_res->ErrMsg() = err_msg; +} + BoolQueryParser::BoolQueryParser(uint32_t a, Json::Value& v) :appid(a),value(v) { @@ -35,43 +41,84 @@ BoolQueryParser::~BoolQueryParser(){ } } -void 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)){ term_query_parser = new TermQueryParser(appid, value[TERM]); - term_query_parser->ParseContent(query_parser_res, type); + return term_query_parser->ParseContent(query_parser_res, type); } else if(value.isMember(MATCH)){ match_query_parser = new MatchQueryParser(appid, value[MATCH]); - match_query_parser->ParseContent(query_parser_res, type); + return match_query_parser->ParseContent(query_parser_res, type); } else if(value.isMember(RANGE)){ range_query_parser = new RangeQueryParser(appid, value[RANGE]); - range_query_parser->ParseContent(query_parser_res, type); + return range_query_parser->ParseContent(query_parser_res, type); } else if(value.isMember(GEODISTANCE)){ geo_query_parser = new GeoDistanceParser(appid, value[GEODISTANCE]); - geo_query_parser->ParseContent(query_parser_res); + return geo_query_parser->ParseContent(query_parser_res); + } else { + SetErrMsg(query_parser_res, "BoolQueryParser only support term/match/range/geo_distance!"); + return -RT_PARSE_CONTENT_ERROR; } + return 0; } -void BoolQueryParser::ParseContent(QueryParserRes* query_parser_res){ +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++){ - DoJobByType(must[i], type, query_parser_res); + ret = DoJobByType(must[i], type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } } } else if (must.isObject()){ - DoJobByType(must, type, query_parser_res); + ret = DoJobByType(must, type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } } - } else if (value.isMember(SHOULD)){ + } + if (value.isMember(SHOULD)){ int type = ORKEY; Json::Value should = value[SHOULD]; if(should.isArray()){ for(int i = 0; i < (int)should.size(); i++){ - DoJobByType(should[i], type, query_parser_res); + ret = DoJobByType(should[i], type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } } } else if (should.isObject()){ - DoJobByType(should, type, query_parser_res); + ret = DoJobByType(should, type, query_parser_res); + if(ret != 0){ + log_error("DoJobByType error!"); + return -RT_PARSE_CONTENT_ERROR; + } } } - return; + 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 7595847..f6d61d2 100644 --- a/src/search_local/index_read/query/bool_query_parser.h +++ b/src/search_local/index_read/query/bool_query_parser.h @@ -31,10 +31,10 @@ public: BoolQueryParser(uint32_t a, Json::Value& v); ~BoolQueryParser(); - void ParseContent(QueryParserRes* query_parser_res); + int ParseContent(QueryParserRes* query_parser_res); private: - void 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; 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 1e218a4..2835e71 100644 --- a/src/search_local/index_read/query/geo_distance_parser.cc +++ b/src/search_local/index_read/query/geo_distance_parser.cc @@ -3,6 +3,8 @@ #include const char* const DISTANCE ="distance"; +const int GEO_PRECISION = 6; +const int DEFAULT_DISTANCE = 2; GeoDistanceParser::GeoDistanceParser(uint32_t a, Json::Value& v) :appid(a),value(v) @@ -22,7 +24,7 @@ vector splitDouble(const string& src, string separate_character) int separate_characterLen = separate_character.size(); int lastPosition = 0, index = -1; string str; - int pos = 0; + double pos = 0; while (-1 != (index = src.find(separate_character, lastPosition))) { if (src.substr(lastPosition, index - lastPosition) != " ") { @@ -33,13 +35,19 @@ vector splitDouble(const string& src, string separate_character) lastPosition = index + separate_characterLen; } string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容 - if (!lastString.empty() && lastString != " ") + if (!lastString.empty() && lastString != " "){ pos = atof(lastString.c_str()); strs.push_back(pos);//如果最后一个分隔符后还有内容就入队 + } return strs; } -void GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ +void SetErrMsg(QueryParserRes* query_parser_res, string err_msg){ + log_error(err_msg.c_str()); + query_parser_res->ErrMsg() = err_msg; +} + +int GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ vector fieldInfos; double distance = 0; string fieldname; @@ -50,6 +58,9 @@ void GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ if(DISTANCE == *iter){ if(geo_value.isString()){ distance = atof(geo_value.asString().c_str()); + } else { + SetErrMsg(query_parser_res, "GeoDistanceParser distance should be string, the unit is km."); + return -RT_PARSE_CONTENT_ERROR; } } else { fieldname = *iter; @@ -59,6 +70,9 @@ void GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ if(res.size() >= 2){ geo.lat = res[0]; geo.lon = res[1]; + } else { + SetErrMsg(query_parser_res, "GeoDistanceParser format error."); + return -RT_PARSE_CONTENT_ERROR; } } else if (geo_value.isArray()){ if(geo_value.size() >= 2){ @@ -68,18 +82,33 @@ void GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ if(geo_value[1].isDouble()){ geo.lat = geo_value[1].asDouble(); } + } else { + SetErrMsg(query_parser_res, "GeoDistanceParser format 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; } 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; } + } else { + SetErrMsg(query_parser_res, "GeoDistanceParser error, value is not string/array/object."); + return -RT_PARSE_CONTENT_ERROR; } } } - vector gisCode = GetArroundGeoHash(geo, distance, 6); + if(distance == 0){ + distance = DEFAULT_DISTANCE; + } + vector gisCode = GetArroundGeoHash(geo, distance, GEO_PRECISION); if(gisCode.size() > 0){ vector fieldInfos; uint32_t segment_tag = 0; @@ -107,5 +136,5 @@ void GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){ query_parser_res->Longitude() = sslon.str(); query_parser_res->Distance() = distance; } - return; + 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 4789742..24a1690 100644 --- a/src/search_local/index_read/query/geo_distance_parser.h +++ b/src/search_local/index_read/query/geo_distance_parser.h @@ -27,7 +27,7 @@ class GeoDistanceParser : public QueryParser public: GeoDistanceParser(uint32_t a, Json::Value& v); ~GeoDistanceParser(); - void ParseContent(QueryParserRes* query_parser_res); + int ParseContent(QueryParserRes* query_parser_res); private: uint32_t appid; 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 8e4e1ff..1670234 100644 --- a/src/search_local/index_read/query/match_query_parser.cc +++ b/src/search_local/index_read/query/match_query_parser.cc @@ -12,11 +12,11 @@ MatchQueryParser::~MatchQueryParser(){ } -void MatchQueryParser::ParseContent(QueryParserRes* query_parser_res){ - ParseContent(query_parser_res, ORKEY); +int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res){ + return ParseContent(query_parser_res, ORKEY); } -void MatchQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){ +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(); @@ -26,7 +26,8 @@ void MatchQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t t fieldname = *iter; field_value = value[fieldname]; } else { - return; + log_error("TermQueryParser error, value is null"); + return -RT_PARSE_CONTENT_ERROR; } uint32_t segment_tag = 0; FieldInfo fieldInfo; @@ -53,11 +54,13 @@ void MatchQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t t } if(fieldInfos.size() != 0){ - if(type == ORKEY){ - query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } else { - query_parser_res->FieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } + 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; + 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 16e777e..38345d1 100644 --- a/src/search_local/index_read/query/match_query_parser.h +++ b/src/search_local/index_read/query/match_query_parser.h @@ -26,8 +26,8 @@ class MatchQueryParser : public QueryParser public: MatchQueryParser(uint32_t a, Json::Value& v); ~MatchQueryParser(); - void ParseContent(QueryParserRes* query_parser_res); - void ParseContent(QueryParserRes* query_parser_res, uint32_t type); + int ParseContent(QueryParserRes* query_parser_res); + int ParseContent(QueryParserRes* query_parser_res, uint32_t type); private: uint32_t appid; diff --git a/src/search_local/index_read/query/query_parser.h b/src/search_local/index_read/query/query_parser.h index 0d777d9..d3a1aa6 100644 --- a/src/search_local/index_read/query/query_parser.h +++ b/src/search_local/index_read/query/query_parser.h @@ -32,6 +32,9 @@ public: map >& OrFieldKeysMap(){ return or_field_keys_map; } + map >& InvertFieldKeysMap(){ + return invert_field_keys_map; + } vector& ExtraFilterKeys(){ return extra_filter_keys; } @@ -53,13 +56,18 @@ public: double& Distance(){ return distance; } + string& ErrMsg(){ + return err_msg; + } private: uint32_t m_has_gis; string latitude; string longitude; double distance; + string err_msg; map > 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; @@ -67,7 +75,7 @@ private: class QueryParser{ public: - virtual void ParseContent(QueryParserRes* query_parser_res) = 0; + virtual int ParseContent(QueryParserRes* query_parser_res) = 0; virtual ~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 8d74b26..fe2cb4a 100644 --- a/src/search_local/index_read/query/range_query_parser.cc +++ b/src/search_local/index_read/query/range_query_parser.cc @@ -16,11 +16,11 @@ RangeQueryParser::~RangeQueryParser(){ } -void RangeQueryParser::ParseContent(QueryParserRes* query_parser_res){ - ParseContent(query_parser_res, ORKEY); +int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res){ + return ParseContent(query_parser_res, ORKEY); } -void RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){ +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(); @@ -42,6 +42,8 @@ void RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t t } 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]; @@ -51,20 +53,43 @@ void RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t t } 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); } - fieldInfo.start = start.asInt(); - fieldInfo.end = end.asInt(); - 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 { + } 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)); + } } + } else { + log_error("RangeQueryParser error, value is null"); + return -RT_PARSE_CONTENT_ERROR; } - return; + 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 fe1c5d9..c2ed204 100644 --- a/src/search_local/index_read/query/range_query_parser.h +++ b/src/search_local/index_read/query/range_query_parser.h @@ -26,8 +26,8 @@ class RangeQueryParser : public QueryParser public: RangeQueryParser(uint32_t a, Json::Value& v); ~RangeQueryParser(); - void ParseContent(QueryParserRes* query_parser_res); - void ParseContent(QueryParserRes* query_parser_res, uint32_t type); + int ParseContent(QueryParserRes* query_parser_res); + int ParseContent(QueryParserRes* query_parser_res, uint32_t type); private: uint32_t appid; 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 234f3ad..0f1607e 100644 --- a/src/search_local/index_read/query/term_query_parser.cc +++ b/src/search_local/index_read/query/term_query_parser.cc @@ -12,11 +12,11 @@ TermQueryParser::~TermQueryParser(){ } -void TermQueryParser::ParseContent(QueryParserRes* query_parser_res){ - ParseContent(query_parser_res, ORKEY); +int TermQueryParser::ParseContent(QueryParserRes* query_parser_res){ + return ParseContent(query_parser_res, ORKEY); } -void TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){ +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(); @@ -28,7 +28,8 @@ void TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t ty json_value = value[fieldname]; field_value = json_value.asString(); } else { - return; + log_error("TermQueryParser error, value is null"); + return -RT_PARSE_CONTENT_ERROR; } uint32_t segment_tag = 0; FieldInfo fieldInfo; @@ -45,9 +46,7 @@ void TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t ty } else if (type == INVERTKEY) { query_parser_res->ExtraFilterInvertKeys().push_back(extra_filter_key); } - return; - } - if (field != 0) + } else if (field != 0) { fieldInfo.word = field_value; fieldInfos.push_back(fieldInfo); @@ -55,9 +54,11 @@ void TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t ty if(fieldInfos.size() != 0){ if(type == ORKEY){ query_parser_res->OrFieldKeysMap().insert(make_pair(fieldInfo.field, fieldInfos)); - } else { + } 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; + 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 a43027c..56321b4 100644 --- a/src/search_local/index_read/query/term_query_parser.h +++ b/src/search_local/index_read/query/term_query_parser.h @@ -26,8 +26,8 @@ class TermQueryParser : public QueryParser public: TermQueryParser(uint32_t a, Json::Value& v); ~TermQueryParser(); - void ParseContent(QueryParserRes* query_parser_res); - void ParseContent(QueryParserRes* query_parser_res, uint32_t type); + int ParseContent(QueryParserRes* query_parser_res); + int ParseContent(QueryParserRes* query_parser_res, uint32_t type); private: uint32_t appid; diff --git a/src/search_local/index_read/search_task.cc b/src/search_local/index_read/search_task.cc index 71f0462..b7ee2c3 100644 --- a/src/search_local/index_read/search_task.cc +++ b/src/search_local/index_read/search_task.cc @@ -597,7 +597,14 @@ int SearchTask::Process(CTaskRequest *request) skipList.InitList(); component->InitSwitch(); log_debug("m_Data: %s", m_Primary_Data.c_str()); - component->GetQueryWord(m_has_gis); + string err_msg = ""; + int ret = component->GetQueryWord(m_has_gis, err_msg); + if (ret != 0) { + string str = GenReplyStr(PARAMETER_ERR, err_msg); + request->setResult(str); + common::ProfilerMonitor::GetInstance().FunctionError(caller_info); + return ret; + } if(component->TerminalTag() == 1 && component->TerminalTagValid() == false){ log_error("TerminalTag is 1 and TerminalTagValid is false."); common::ProfilerMonitor::GetInstance().FunctionError(caller_info); @@ -634,7 +641,7 @@ int SearchTask::Process(CTaskRequest *request) } } logical_operate = new LogicalOperate(m_appid, m_sort_type, m_has_gis, component->CacheSwitch()); - int ret = DoJob(request); + ret = DoJob(request); if (ret != 0) { string str = GenReplyStr(PARAMETER_ERR); request->setResult(str);