convert tab to spaces

This commit is contained in:
shzhulin3 2021-04-29 17:44:42 +08:00
parent 79f2d07c15
commit fb6a8f3d02
11 changed files with 312 additions and 312 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -18,28 +18,28 @@ GeoDistanceParser::~GeoDistanceParser(){
vector<double> splitDouble(const string& src, string separate_character)
{
vector<double> strs;
vector<double> 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<FieldInfo> 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<string> gisCode = GetArroundGeoHash(geo, distance, GEO_PRECISION);
if(gisCode.size() > 0){
vector<FieldInfo> 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<FieldInfo> 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;
}

View File

@ -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;
};

View File

@ -18,49 +18,49 @@ int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res){
int MatchQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
vector<FieldInfo> 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<string> 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<string> 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;
}

View File

@ -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

View File

@ -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<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;
vector<ExtraFilterKey> extra_filter_keys;
vector<ExtraFilterKey> extra_filter_and_keys;
vector<ExtraFilterKey> extra_filter_invert_keys;
vector<ExtraFilterKey> extra_filter_and_keys;
vector<ExtraFilterKey> extra_filter_invert_keys;
};
class QueryParser{

View File

@ -22,74 +22,74 @@ int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res){
int RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
vector<FieldInfo> 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;
}

View File

@ -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

View File

@ -18,47 +18,47 @@ int TermQueryParser::ParseContent(QueryParserRes* query_parser_res){
int TermQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t type){
vector<FieldInfo> 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;
}

View File

@ -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