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
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);
60  unsigned int getErrorCode(void);
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  unsigned long long getTimeoutedRequests(void) const;
72  void resetTimeoutedRequests(void);
73 
74  void setDefaultRequestTimeout(unsigned long defaultRequestTimeout_);
75  unsigned long getDefaultRequestTimeout(void) const;
76 
77  void setCheckIncomingDocuments(bool checkIncomingDocuments_) {checkIncomingDocuments=checkIncomingDocuments_;}
78  bool getCheckIncomingDocuments(void) const {return checkIncomingDocuments;}
79 
80  void setPackIncomingDocuments(bool packIncomingDocuments_) {packIncomingDocuments=packIncomingDocuments_;}
81  bool getPackIncomingDocuments(void) const {return packIncomingDocuments;}
82 
83  void setMinNumberFieldsPacking(unsigned int minNumberFieldsPacking_) {minNumberFieldsPacking=minNumberFieldsPacking_;}
84  unsigned int getMinNumberFieldsPacking(void) const {return minNumberFieldsPacking;}
85 
86  void resetLogStream(void);
87  void setLogStream(std::ostream& os);
88 
89  std::string logMsg(bool isReset=true);
90  std::ostream& log(void);
91 
92  void setLoggable(Loggable loggable);
93  void resetLoggable(void);
94 
95  void parseHostPort(const std::string& in, std::string& host, unsigned int& port) throw (std::exception);
96 
97  CustomMessage& getCustomMessage(void) {return message;}
98 
99  void setMatchMode(unsigned int matchMode_) {matchMode=matchMode_;}
100  unsigned int getMatchMode(void) const {return matchMode;}
101 
102  void setSortMode(unsigned int sortMode_) {sortMode=sortMode_;}
103  unsigned int getSortMode(void) const {return sortMode;}
104 
105  void setRankingMode(unsigned int rankingMode_, const std::string& rankExpression_="");
106  unsigned int getRankingMode(void) const {return rankingMode;}
107 
108  void setRankExpression(const std::string& rankExpression_) {rankExpression=rankExpression_;}
109  std::string getRankExpression(void) const {return rankExpression;}
110 private:
111  std::string makeDefaultJSON(const std::string& logMsg);
112 private:
113  SphinxSearcher searcher;
114  SphinxIndexer indexer;
115 
116  bool loaded;
117  bool checkIncomingDocuments;
118  bool packIncomingDocuments;
119  unsigned int minNumberFieldsPacking;
120 
121  LoggerStream logger;
122 
123  MessagesCollection messagesCollection;
124  CustomMessage message;
125 
126  unsigned int matchMode;
127  unsigned int sortMode;
128  unsigned int rankingMode;
129  std::string rankExpression;
130 
131  typedef SphinxSearchInterface inherited;
132 };
133 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
135 } // namespace sphinx
136 } // namespace HCE
137 
138 #endif // SPHINX_FUNCTIONAL_OBJECT_HPP