complete bool query
This commit is contained in:
parent
96b193cbdb
commit
d0f422521a
@ -21,6 +21,10 @@
|
|||||||
#include "db_manager.h"
|
#include "db_manager.h"
|
||||||
#include "utf8_str.h"
|
#include "utf8_str.h"
|
||||||
#include "query/bool_query_parser.h"
|
#include "query/bool_query_parser.h"
|
||||||
|
#include "query/geo_distance_parser.h"
|
||||||
|
#include "query/range_query_parser.h"
|
||||||
|
#include "query/match_query_parser.h"
|
||||||
|
#include "query/term_query_parser.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -218,6 +222,14 @@ void Component::GetQueryWord(uint32_t &m_has_gis){
|
|||||||
if(m_query.isObject()){
|
if(m_query.isObject()){
|
||||||
if(m_query.isMember("bool")){
|
if(m_query.isMember("bool")){
|
||||||
query_parser = new BoolQueryParser(m_appid, m_query["bool"]);
|
query_parser = new BoolQueryParser(m_appid, m_query["bool"]);
|
||||||
|
} else if(m_query.isMember("geo_distance")){
|
||||||
|
query_parser = new GeoDistanceParser(m_appid, m_query["geo_distance"]);
|
||||||
|
} else if(m_query.isMember("range")){
|
||||||
|
query_parser = new RangeQueryParser(m_appid, m_query["range"]);
|
||||||
|
} else if(m_query.isMember("match")){
|
||||||
|
query_parser = new MatchQueryParser(m_appid, m_query["match"]);
|
||||||
|
} else if(m_query.isMember("term")){
|
||||||
|
query_parser = new TermQueryParser(m_appid, m_query["term"]);
|
||||||
}
|
}
|
||||||
query_parser_res = new QueryParserRes();
|
query_parser_res = new QueryParserRes();
|
||||||
query_parser->ParseContent(query_parser_res);
|
query_parser->ParseContent(query_parser_res);
|
||||||
@ -234,6 +246,7 @@ void Component::GetQueryWord(uint32_t &m_has_gis){
|
|||||||
latitude = query_parser_res->Latitude();
|
latitude = query_parser_res->Latitude();
|
||||||
longitude = query_parser_res->Longitude();
|
longitude = query_parser_res->Longitude();
|
||||||
distance = query_parser_res->Distance();
|
distance = query_parser_res->Distance();
|
||||||
|
log_debug("lat: %s, lon: %s, distance: %f", latitude.c_str(), longitude.c_str(), distance);
|
||||||
}
|
}
|
||||||
extra_filter_keys.assign(query_parser_res->ExtraFilterKeys().begin(), query_parser_res->ExtraFilterKeys().end());
|
extra_filter_keys.assign(query_parser_res->ExtraFilterKeys().begin(), query_parser_res->ExtraFilterKeys().end());
|
||||||
extra_filter_and_keys.assign(query_parser_res->ExtraFilterAndKeys().begin(), query_parser_res->ExtraFilterAndKeys().end());
|
extra_filter_and_keys.assign(query_parser_res->ExtraFilterAndKeys().begin(), query_parser_res->ExtraFilterAndKeys().end());
|
||||||
|
@ -4,13 +4,15 @@
|
|||||||
#include "range_query_parser.h"
|
#include "range_query_parser.h"
|
||||||
#include "term_query_parser.h"
|
#include "term_query_parser.h"
|
||||||
#include "match_query_parser.h"
|
#include "match_query_parser.h"
|
||||||
|
#include "geo_distance_parser.h"
|
||||||
|
|
||||||
const char* const BoolQueryParser::NAME ="bool";
|
const char* const NAME ="bool";
|
||||||
const char* const BoolQueryParser::MUST ="must";
|
const char* const MUST ="must";
|
||||||
const char* const BoolQueryParser::SHOULD ="should";
|
const char* const SHOULD ="should";
|
||||||
const char* const BoolQueryParser::TERM ="term";
|
const char* const TERM ="term";
|
||||||
const char* const BoolQueryParser::MATCH ="match";
|
const char* const MATCH ="match";
|
||||||
const char* const BoolQueryParser::RANGE ="range";
|
const char* const RANGE ="range";
|
||||||
|
const char* const GEODISTANCE ="geo_distance";
|
||||||
|
|
||||||
BoolQueryParser::BoolQueryParser(uint32_t a, Json::Value& v)
|
BoolQueryParser::BoolQueryParser(uint32_t a, Json::Value& v)
|
||||||
:appid(a),value(v)
|
:appid(a),value(v)
|
||||||
@ -28,6 +30,9 @@ BoolQueryParser::~BoolQueryParser(){
|
|||||||
if(NULL != match_query_parser){
|
if(NULL != match_query_parser){
|
||||||
delete match_query_parser;
|
delete match_query_parser;
|
||||||
}
|
}
|
||||||
|
if(NULL != geo_query_parser){
|
||||||
|
delete geo_query_parser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolQueryParser::DoJobByType(Json::Value& value, uint32_t type, QueryParserRes* query_parser_res){
|
void BoolQueryParser::DoJobByType(Json::Value& value, uint32_t type, QueryParserRes* query_parser_res){
|
||||||
@ -40,6 +45,9 @@ void BoolQueryParser::DoJobByType(Json::Value& value, uint32_t type, QueryParser
|
|||||||
} 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]);
|
||||||
range_query_parser->ParseContent(query_parser_res, type);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
class RangeQueryParser;
|
class RangeQueryParser;
|
||||||
class TermQueryParser;
|
class TermQueryParser;
|
||||||
class MatchQueryParser;
|
class MatchQueryParser;
|
||||||
|
class GeoDistanceParser;
|
||||||
class BoolQueryParser : public QueryParser
|
class BoolQueryParser : public QueryParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -38,15 +39,10 @@ private:
|
|||||||
private:
|
private:
|
||||||
uint32_t appid;
|
uint32_t appid;
|
||||||
Json::Value value;
|
Json::Value value;
|
||||||
static const char* const NAME;
|
|
||||||
static const char* const MUST;
|
|
||||||
static const char* const SHOULD;
|
|
||||||
static const char* const TERM;
|
|
||||||
static const char* const MATCH;
|
|
||||||
static const char* const RANGE;
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -102,8 +102,8 @@ void GeoDistanceParser::ParseContent(QueryParserRes* query_parser_res){
|
|||||||
stringstream sslat;
|
stringstream sslat;
|
||||||
stringstream sslon;
|
stringstream sslon;
|
||||||
sslat << geo.lat;
|
sslat << geo.lat;
|
||||||
sslon << geo.lon;
|
|
||||||
query_parser_res->Latitude() = sslat.str();
|
query_parser_res->Latitude() = sslat.str();
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
return latitude;
|
return latitude;
|
||||||
}
|
}
|
||||||
string& Longitude(){
|
string& Longitude(){
|
||||||
return latitude;
|
return longitude;
|
||||||
}
|
}
|
||||||
double& Distance(){
|
double& Distance(){
|
||||||
return distance;
|
return distance;
|
||||||
|
@ -53,9 +53,10 @@ void RangeQueryParser::ParseContent(QueryParserRes* query_parser_res, uint32_t t
|
|||||||
info.range_type = RANGE_GTLT;
|
info.range_type = RANGE_GTLT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info.start = start.asInt();
|
fieldInfo.start = start.asInt();
|
||||||
info.end = end.asInt();
|
fieldInfo.end = end.asInt();
|
||||||
fieldInfos.push_back(info);
|
fieldInfo.range_type = info.range_type;
|
||||||
|
fieldInfos.push_back(fieldInfo);
|
||||||
}
|
}
|
||||||
if(fieldInfos.size() != 0){
|
if(fieldInfos.size() != 0){
|
||||||
if(type == ORKEY){
|
if(type == ORKEY){
|
||||||
|
Loading…
Reference in New Issue
Block a user