xapian-core  2.1.0
remoteserver.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2006-2026 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 #include <string_view>
35 
39  void operator=(const RemoteServer &);
40 
43 
48  Xapian::Database* db = nullptr;
49 
51  Xapian::WritableDatabase* wdb = nullptr;
52 
54  bool writable;
55 
62 
68  double idle_timeout;
69 
72 
75  message_type get_message(double timeout, std::string & result,
76  message_type required_type = MSG_MAX);
77 
80  void send_message(reply_type type, std::string_view message);
81 
84  void send_message(reply_type type, std::string_view message,
85  double end_time) {
86  unsigned char type_as_char = static_cast<unsigned char>(type);
87  RemoteConnection::send_message(type_as_char, message, end_time);
88  }
89 
90  // all terms
92  void msg_allterms(std::string_view message);
93 
94  // get document
96  void msg_document(std::string_view message);
97 
98  // term exists?
100  void msg_termexists(std::string_view message);
101 
102  // get collection freq
104  void msg_collfreq(std::string_view message);
105 
106  // get termfreq
108  void msg_termfreq(std::string_view message);
109 
110  // get termfreq and collection freq
112  void msg_freqs(std::string_view message);
113 
114  // get value statistics
116  void msg_valuestats(std::string_view message);
117 
118  // keep alive
120  void msg_keepalive(std::string_view message);
121 
122  // get doclength
124  void msg_doclength(std::string_view message);
125 
126  // set the query; return the mset
128  void msg_query(std::string_view message);
129 
130  // get termlist
132  void msg_termlist(std::string_view message);
133 
134  // get postlist
136  void msg_postlist(std::string_view message);
137 
138  // get positionlist
140  void msg_positionlist(std::string_view message);
141 
142  // get positionlist count
144  void msg_positionlistcount(std::string_view message);
145 
146  // get write access
148  void msg_writeaccess(std::string_view message);
149 
150  // reopen
152  void msg_reopen(std::string_view message);
153 
154  // get updated doccount and avlength
156  void msg_update(std::string_view message);
157 
158  // commit
160  void msg_commit(std::string_view message);
161 
162  // cancel
164  void msg_cancel(std::string_view message);
165 
166  // add document
168  void msg_adddocument(std::string_view message);
169 
170  // delete document
172  void msg_deletedocument(std::string_view message);
173 
174  // delete document with unique term
176  void msg_deletedocumentterm(std::string_view message);
177 
178  // replace document
180  void msg_replacedocument(std::string_view message);
181 
182  // replace document with unique term
184  void msg_replacedocumentterm(std::string_view message);
185 
186  // get metadata
188  void msg_getmetadata(std::string_view message);
189 
190  // read metadata key list
192  void msg_metadatakeylist(std::string_view message);
193 
194  // set metadata
196  void msg_setmetadata(std::string_view message);
197 
198  // request a document (pre-fetch hint)
200  void msg_requestdocument(std::string_view message);
201 
202  // add a spelling
204  void msg_addspelling(std::string_view message);
205 
206  // remove a spelling
208  void msg_removespelling(std::string_view message);
209 
210  // get number of unique terms
212  void msg_uniqueterms(std::string_view message);
213 
214  // get max_wdf
216  void msg_wdfdocmax(std::string_view message);
217 
218  // reconstruct document text
220  void msg_reconstructtext(std::string_view message);
221 
222  // get synonyms for a term
224  void msg_synonymtermlist(std::string_view message);
225 
226  // get terms with an entry in synonym table, starting with a prefix
228  void msg_synonymkeylist(std::string_view message);
229 
230  // add a synonym
232  void msg_addsynonym(std::string_view message);
233 
234  // remove a synonym
236  void msg_removesynonym(std::string_view message);
237 
238  // clear synonyms for a term
240  void msg_clearsynonyms(std::string_view message);
241 
242  public:
255  RemoteServer(const std::vector<std::string> &dbpaths,
256  int fdin, int fdout,
257  double active_timeout_,
258  double idle_timeout_,
259  bool writable = false);
260 
262  ~RemoteServer();
263 
269  void run();
270 
272  void set_registry(const Xapian::Registry & reg_) { reg = reg_; }
273 };
274 
275 #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:37
void set_registry(const Xapian::Registry &reg_)
Set the registry used for (un)serialisation.
Definition: remoteserver.h:272
double idle_timeout
Timeout while waiting for a new action from the client.
Definition: remoteserver.h:68
Xapian::Registry reg
The registry, which allows unserialisation of user subclasses.
Definition: remoteserver.h:71
double active_timeout
Timeout for actions during a conversation.
Definition: remoteserver.h:61
bool writable
Do we support writing?
Definition: remoteserver.h:54
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:84
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:963
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.