HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxInputJsonMessage.hpp
Go to the documentation of this file.
1 
14 #ifndef SPHINX_INPUT_JSON_MESSAGE_HPP
15 #define SPHINX_INPUT_JSON_MESSAGE_HPP
16 
17 #include <iostream>
18 #include <vector>
19 
20 #include "JsonSerializable.hpp"
21 
22 namespace HCE
23 {
24 namespace sphinx
25 {
26 //-----------------------------------------------------------------------------
27 namespace input_json_message_const
28 {
29  const std::string messageType = "type";
30  const std::string messageBody = "data";
31  const std::string messageTTL = "ttl";
32  const unsigned int defaultTTLValue = 1;
33 
34  const std::string queryString = "q";
35  const std::string filtersJsonArray = "filters";
36  const std::string queryParameters = "parameters";
37  const std::string orderParameters = "order";
38 
39  const std::string filterType = "type";
40  const std::string attributeName = "attribute";
41  const std::string attributeValues = "values";
42  const std::string excludeValue = "exclude";
43  const std::string maxResultsNumber = "max_results";
44 
45  const std::string timeoutValueName = "timeout";
46  const unsigned long long defaultTimeoutValue = 1000;
47 
48  const unsigned int defaultMaxResultsNumber = 1000;
49  const unsigned int defaultMaxAttributesNumber = 50;
50  const unsigned int defaultMaxWordsNumber = 10;
51  const unsigned int extraAttributesNumber = 2; // need for ID docs and weight
52 
53  const std::string offsetResultsNumber = "offset";
54  const std::string limitResultsNumber = "limit";
55  const std::string cutoffResultNumber = "cutoff";
56 
57  const std::string indexName = "name";
58  const std::string documentFile = "body";
59 
60  const std::string commandString = "command";
61  const std::string commandOptionsString = "options";
62 
63  const std::string queryId = "queryId";
64  const std::string JsonType = "JsonType";
65  const std::string sortFieldName = "sort_by";
66  const std::string sortOrderBy = "order_by";
67  const std::string externalFieldsNames = "return_json_ext_fields";
68  const std::string weightAlgorithm = "algorithm";
69  const std::string orderFieldsNames = "fields";
70  const std::string orderBy = "order_by";
71 }
72 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 {
76 public:
77  enum class MessageType
78  {
79  mtSearch=0,
80  mtIndex=1,
81  mtManage=2
82  };
83 public:
84  explicit SphinxInputJsonMessage(const std::string& json="");
86  virtual ~SphinxInputJsonMessage(void) {};
87 
88  bool serialize(std::string& json);
89  bool unserialize(const std::string& json);
90 
91  void setType(SphinxInputJsonMessage::MessageType messageType_) {messageType=messageType_;}
92  SphinxInputJsonMessage::MessageType getType(void) const {return messageType;}
93 
94  void setData(const std::string& messageBody_) {messageBody=messageBody_;}
95  std::string getData(void) {return messageBody;}
96 
97  void setTTL(unsigned int ttl) {messageTTL=ttl;}
98  unsigned int getTTL(void) const {return messageTTL;}
99 private:
100  MessageType messageType;
101  std::string messageBody;
102  unsigned int messageTTL;
103 
104 private:
105  friend std::istream& operator>>(std::istream& is, SphinxInputJsonMessage& jsonHandler);
106  friend std::ostream& operator<<(std::ostream& os, const SphinxInputJsonMessage& jsonHandler);
107  typedef IJsonSerializable inherited;
108 };
109 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
111 } // end namespace sphinx
112 } // end namespace HCE
113 
114 #endif // SPHINX_INPUT_JSON_MESSAGE_HPP