hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxFunctionalObject.hpp
Go to the documentation of this file.
1 
14 #ifndef SPHINX_FUNCTIONAL_OBJECT_HPP
15 #define SPHINX_FUNCTIONAL_OBJECT_HPP
16 
17 #include <sstream>
19 #include "SphinxNodeOptions.hpp"
20 #include "SphinxSearcher.hpp"
21 #include "SphinxIndexer.hpp"
22 #include "LoggerStream.hpp"
23 #include "CustomMessage.hpp"
24 
25 namespace HCE
26 {
27 namespace sphinx
28 {
29 class SphinxInputJsonMessage;
30 class SphinxOutputJsonMessage;
31 //-----------------------------------------------------------------------------
33 {
34 public:
35  explicit SphinxFunctionalObject(const std::string& nodeName_="", const std::string& homeDir_=sphinx_search_const::defaultHomeDir,
36  const std::string& indexName_="", bool startSearchd_=false, bool stopSearchd_=false);
37  SphinxFunctionalObject(const std::string& nodeName_, unsigned int nodeNumber, const std::string& homeDir_=sphinx_search_const::defaultHomeDir,
38  const std::string& indexName_="", bool startSearchd_=false, bool stopSearchd_=false);
39  virtual ~SphinxFunctionalObject(void);
40 
41  bool loadConfiguration(const std::string& indexName); // indexer config
42  std::string Process(const std::string& json); // make search (black box)
44 
45  void resizeResultData(size_t matchesCount, size_t attributesCount);
46  bool isLoadedConfig(void) const {return loaded;};
47 
48  bool easyStart(void);
49  bool startSearchd(void);
50  bool stopSearchd(void);
51  bool isActiveSearchd(void);
52  bool isConnected(void) const;
53 
54  bool open(void); // persistence connection
55  bool close(void); // close connection
56 
57  void resetError(void);
58  void applyError(const std::string& msg, unsigned int code);
59  std::string getErrorMsg(void) const;
60  unsigned int getErrorCode(void) const;
61 
62  void setServerHost(const std::string& serverHost_);
63  std::string getServerHost(void) const;
64 
65  void setServerPort(int serverPort_);
66  int getServerPort(void) const;
67 
68  bool setIndexFileName(const std::string& indexFileName_);
69  std::string getIndexFileName(void) const;
70 
71  void setTimeoutedRequests(unsigned long long timeoutedRequests_);
72  unsigned long long getTimeoutedRequests(void) const;
73  void resetTimeoutedRequests(void);
74 
75  void setDefaultRequestTimeout(unsigned long defaultRequestTimeout_);
76  unsigned long getDefaultRequestTimeout(void) const;
77 
78  void setCheckIncomingDocuments(bool checkIncomingDocuments_) {checkIncomingDocuments=checkIncomingDocuments_;}
79  bool getCheckIncomingDocuments(void) const {return checkIncomingDocuments;}
80 
81  void setPackIncomingDocuments(bool packIncomingDocuments_) {packIncomingDocuments=packIncomingDocuments_;}
82  bool getPackIncomingDocuments(void) const {return packIncomingDocuments;}
83 
84  void setMinNumberFieldsPacking(unsigned int minNumberFieldsPacking_) {minNumberFieldsPacking=minNumberFieldsPacking_;}
85  unsigned int getMinNumberFieldsPacking(void) const {return minNumberFieldsPacking;}
86 
87  void resetLogStream(void);
88  void setLogStream(std::ostream& os);
89 
90  std::string logMsg(bool isReset=true);
91  std::ostream& log(LoggerStream::Priority logPriority);
92 
93  void setLoggable(Loggable loggable);
94  void resetLoggable(void);
95 
96  static void parseHostPort(const std::string& in, std::string& host, unsigned int& port) throw (std::exception);
97 
98  CustomMessage& getCustomMessage(void) {return message;}
99 
100  void setMatchMode(unsigned int matchMode_) {matchMode=matchMode_;}
101  unsigned int getMatchMode(void) const {return matchMode;}
102 
103  void setSortMode(unsigned int sortMode_) {sortMode=sortMode_;}
104  unsigned int getSortMode(void) const {return sortMode;}
105 
106  void setRankingMode(unsigned int rankingMode_, const std::string& rankerExpression_="");
107  unsigned int getRankingMode(void) const {return rankingMode;}
108 
109  void setRankerExpression(const std::string& rankerExpression_) {rankerExpression=rankerExpression_;}
110  std::string getRankerExpression(void) const {return rankerExpression;}
111 
112  static std::string makeErrorMessage(const std::string& inputMessage, unsigned int errorCode, const std::string& errorMessage);
113 private:
114  std::string makeDefaultJSON(const std::string& logMsg);
115 private:
116  SphinxSearcher searcher;
117  SphinxIndexer indexer;
118 
119  bool loaded;
120  bool checkIncomingDocuments;
121  bool packIncomingDocuments;
122  unsigned int minNumberFieldsPacking;
123 
124  LoggerStream logger;
125 
126  MessagesCollection messagesCollection;
127  CustomMessage message;
128 
129  unsigned int matchMode;
130  unsigned int sortMode;
131  unsigned int rankingMode;
132  std::string rankerExpression;
133 
134  typedef SphinxSearchInterface inherited;
135 };
136 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
138 } // namespace sphinx
139 } // namespace HCE
140 
141 #endif // SPHINX_FUNCTIONAL_OBJECT_HPP