xapian-core  2.0.0
remoteserver.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2006-2024 Olly Betts
5  * Copyright (C) 2007,2009,2010 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_REMOTESERVER_H
23 #define XAPIAN_INCLUDED_REMOTESERVER_H
24 
25 #include "xapian/database.h"
26 #include "xapian/postingsource.h"
27 #include "xapian/registry.h"
28 #include "xapian/visibility.h"
29 #include "xapian/weight.h"
30 
31 #include "remoteconnection.h"
32 
33 #include <string>
34 
38  void operator=(const RemoteServer &);
39 
42 
47  Xapian::Database* db = nullptr;
48 
50  Xapian::WritableDatabase* wdb = nullptr;
51 
53  bool writable;
54 
61 
67  double idle_timeout;
68 
71 
74  message_type get_message(double timeout, std::string & result,
75  message_type required_type = MSG_MAX);
76 
79  void send_message(reply_type type, std::string_view message);
80 
83  void send_message(reply_type type, std::string_view message,
84  double end_time) {
85  unsigned char type_as_char = static_cast<unsigned char>(type);
86  RemoteConnection::send_message(type_as_char, message, end_time);
87  }
88 
89  // all terms
91  void msg_allterms(const std::string & message);
92 
93  // get document
95  void msg_document(const std::string & message);
96 
97  // term exists?
99  void msg_termexists(const std::string & message);
100 
101  // get collection freq
103  void msg_collfreq(const std::string & message);
104 
105  // get termfreq
107  void msg_termfreq(const std::string & message);
108 
109  // get termfreq and collection freq
111  void msg_freqs(const std::string & message);
112 
113  // get value statistics
115  void msg_valuestats(const std::string & message);
116 
117  // keep alive
119  void msg_keepalive(const std::string & message);
120 
121  // get doclength
123  void msg_doclength(const std::string & message);
124 
125  // set the query; return the mset
127  void msg_query(const std::string & message);
128 
129  // get termlist
131  void msg_termlist(const std::string & message);
132 
133  // get postlist
135  void msg_postlist(const std::string & message);
136 
137  // get positionlist
139  void msg_positionlist(const std::string &message);
140 
141  // get positionlist count
143  void msg_positionlistcount(const std::string &message);
144 
145  // get write access
147  void msg_writeaccess(const std::string & message);
148 
149  // reopen
151  void msg_reopen(const std::string & message);
152 
153  // get updated doccount and avlength
155  void msg_update(const std::string &message);
156 
157  // commit
159  void msg_commit(const std::string & message);
160 
161  // cancel
163  void msg_cancel(const std::string &message);
164 
165  // add document
167  void msg_adddocument(const std::string & message);
168 
169  // delete document
171  void msg_deletedocument(const std::string & message);
172 
173  // delete document with unique term
175  void msg_deletedocumentterm(const std::string & message);
176 
177  // replace document
179  void msg_replacedocument(const std::string & message);
180 
181  // replace document with unique term
183  void msg_replacedocumentterm(const std::string & message);
184 
185  // get metadata
187  void msg_getmetadata(const std::string & message);
188 
189  // read metadata key list
191  void msg_metadatakeylist(const std::string & message);
192 
193  // set metadata
195  void msg_setmetadata(const std::string & message);
196 
197  // request a document (pre-fetch hint)
199  void msg_requestdocument(const std::string& message);
200 
201  // add a spelling
203  void msg_addspelling(const std::string & message);
204 
205  // remove a spelling
207  void msg_removespelling(const std::string & message);
208 
209  // get number of unique terms
211  void msg_uniqueterms(const std::string & message);
212 
213  // get max_wdf
215  void msg_wdfdocmax(const std::string& message);
216 
217  // reconstruct document text
219  void msg_reconstructtext(const std::string& message);
220 
221  // get synonyms for a term
223  void msg_synonymtermlist(const std::string& message);
224 
225  // get terms with an entry in synonym table, starting with a prefix
227  void msg_synonymkeylist(const std::string& message);
228 
229  // add a synonym
231  void msg_addsynonym(const std::string& message);
232 
233  // remove a synonym
235  void msg_removesynonym(const std::string& message);
236 
237  // clear synonyms for a term
239  void msg_clearsynonyms(const std::string& message);
240 
241  public:
254  RemoteServer(const std::vector<std::string> &dbpaths,
255  int fdin, int fdout,
256  double active_timeout_,
257  double idle_timeout_,
258  bool writable = false);
259 
261  ~RemoteServer();
262 
268  void run();
269 
271  void set_registry(const Xapian::Registry & reg_) { reg = reg_; }
272 };
273 
274 #endif // XAPIAN_INCLUDED_REMOTESERVER_H
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
void send_message(char type, std::string_view s, double end_time)
Send a message.
int get_message(std::string &result, double end_time)
Read one message from fdin.
Remote backend server base class.
Definition: remoteserver.h:36
void set_registry(const Xapian::Registry &reg_)
Set the registry used for (un)serialisation.
Definition: remoteserver.h:271
double idle_timeout
Timeout while waiting for a new action from the client.
Definition: remoteserver.h:67
Xapian::Registry reg
The registry, which allows unserialisation of user subclasses.
Definition: remoteserver.h:70
double active_timeout
Timeout for actions during a conversation.
Definition: remoteserver.h:60
bool writable
Do we support writing?
Definition: remoteserver.h:53
RemoteServer(const RemoteServer &)
Don't allow copying.
void send_message(reply_type type, std::string_view message, double end_time)
Send a message to the client, with specific end_time.
Definition: remoteserver.h:83
void operator=(const RemoteServer &)
Don't allow assignment.
An indexed database of documents.
Definition: database.h:75
Registry for user subclasses.
Definition: registry.h:47
This class provides read/write access to a database.
Definition: database.h:964
An indexed database of documents.
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
Definition: realtime.h:95
External sources of posting information.
Class for looking up user subclasses during unserialisation.
RemoteConnection class used by the remote backend.
message_type
Message types (client -> server).
@ MSG_MAX
reply_type
Reply types (server -> client).
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
#define XAPIAN_VISIBILITY_INTERNAL
Definition: visibility.h:29
Weighting scheme API.