xapian-core  2.0.0
backendmanager.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2017,2018 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (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_BACKENDMANAGER_H
23 #define XAPIAN_INCLUDED_BACKENDMANAGER_H
24 
25 #include <xapian.h>
26 #include <vector>
27 
28 // Paths to xapian-tcpsrv and xapian-progsrv.
29 #ifdef __WIN32__
30 // Under __WIN32__ we want \ path separators since we pass this path to
31 // CreateProcess().
32 # define XAPIAN_BIN_PATH "..\\bin\\"
33 # define EXE_SUFFIX ".exe"
34 #else
35 # define XAPIAN_BIN_PATH "../bin/"
36 # define EXE_SUFFIX
37 #endif
38 #define XAPIAN_TCPSRV XAPIAN_BIN_PATH "xapian-tcpsrv" EXE_SUFFIX
39 #define XAPIAN_PROGSRV XAPIAN_BIN_PATH "xapian-progsrv" EXE_SUFFIX
40 
43  std::string datadir;
44 
46  std::string dbtype;
47 
48  protected:
51  const std::vector<std::string> & files);
52 
53  bool create_dir_if_needed(const std::string &dirname);
54 
61  virtual Xapian::Database do_get_database(const std::vector<std::string> &files);
62 
69  virtual std::string do_get_database_path(const std::vector<std::string> &files);
70 
71  public:
73  BackendManager(const std::string& datadir_, const std::string& dbtype_)
74  : datadir(datadir_), dbtype(dbtype_) {}
75 
79  virtual ~BackendManager();
80 
83  const std::string& get_dbtype() const { return dbtype; }
84 
87  const std::string & get_datadir() const { return datadir; }
88 
90  Xapian::Database get_database(const std::vector<std::string> &files);
91 
93  Xapian::Database get_database(const std::string &file);
94 
104  Xapian::Database get_database(const std::string &dbname,
105  void (*gen)(Xapian::WritableDatabase&,
106  const std::string &),
107  const std::string &arg);
108 
110  virtual Xapian::Database get_database_by_path(const std::string& path);
111 
113  std::string get_database_path(const std::vector<std::string> &files);
114 
116  std::string get_database_path(const std::string &file);
117 
119  std::string get_database_path(const std::string &dbname,
120  void (*gen)(Xapian::WritableDatabase&,
121  const std::string &),
122  const std::string &arg);
123 
125  virtual Xapian::WritableDatabase get_writable_database(const std::string & name, const std::string & file);
126 
129  get_remote_writable_database(std::string args);
130 
132  virtual std::string get_writable_database_path(const std::string & name);
133 
136  get_generated_database(const std::string& name);
137 
139  virtual std::string get_generated_database_path(const std::string & name);
140 
142  virtual void finalise_generated_database(const std::string& name);
143 
145  virtual Xapian::Database
146  get_remote_database(const std::vector<std::string>& files,
147  unsigned int timeout,
148  int* port_ptr);
149 
153  virtual std::string get_writable_database_args(const std::string& path,
154  unsigned int timeout);
155 
158 
161 
163  virtual std::string get_writable_database_path_again();
164 
166  virtual std::string get_compaction_output_path(const std::string& name);
167 
172  virtual void clean_up();
173 
178  virtual void kill_remote(const Xapian::Database& db);
179 
181  static const char * get_xapian_progsrv_command();
182 };
183 
184 #endif /* XAPIAN_INCLUDED_BACKENDMANAGER_H */
static const char * get_xapian_progsrv_command()
Get the command line required to run xapian-progsrv.
Xapian::Database get_database(const std::vector< std::string > &files)
Get a database instance of the current type.
virtual std::string get_compaction_output_path(const std::string &name)
Get a path to compact a database to.
virtual Xapian::WritableDatabase get_writable_database_again()
Create a WritableDatabase object for the last opened WritableDatabase.
virtual Xapian::WritableDatabase get_generated_database(const std::string &name)
Get a generated writable database instance.
std::string dbtype
The backend database type (set by subclass ctor).
virtual std::string do_get_database_path(const std::vector< std::string > &files)
Virtual method implementing get_database_path().
bool create_dir_if_needed(const std::string &dirname)
Create the directory dirname if needed.
virtual Xapian::Database do_get_database(const std::vector< std::string > &files)
Virtual method implementing get_database().
void index_files_to_database(Xapian::WritableDatabase &database, const std::vector< std::string > &files)
Index data from zero or more text files into a database.
virtual Xapian::WritableDatabase get_remote_writable_database(std::string args)
Get a remote Xapian::WritableDatabase instance with specified args.
virtual ~BackendManager()
We have virtual methods and want to be able to delete derived classes using a pointer to the base cla...
virtual std::string get_writable_database_args(const std::string &path, unsigned int timeout)
Get the args for opening a writable remote database with the specified timeout.
virtual Xapian::Database get_database_by_path(const std::string &path)
Get a database instance by path.
std::string get_database_path(const std::vector< std::string > &files)
Get the path of a database instance, if such a thing exists.
virtual std::string get_writable_database_path(const std::string &name)
Get the path of a writable database instance, if such a thing exists.
virtual std::string get_generated_database_path(const std::string &name)
Get the path to use for generating a database, if supported.
const std::string & get_dbtype() const
Get the database type currently in use.
virtual Xapian::Database get_writable_database_as_database()
Create a Database object for the last opened WritableDatabase.
BackendManager(const std::string &datadir_, const std::string &dbtype_)
Constructor.
std::string datadir
The current data directory.
virtual void finalise_generated_database(const std::string &name)
Finalise the generated database.
const std::string & get_datadir() const
Get the directory to store data in.
virtual void clean_up()
Called after each test, to perform any necessary cleanup.
virtual Xapian::Database get_remote_database(const std::vector< std::string > &files, unsigned int timeout, int *port_ptr)
Get a remote database instance with the specified timeout.
virtual void kill_remote(const Xapian::Database &db)
Kill the remote server associated with db.
virtual Xapian::WritableDatabase get_writable_database(const std::string &name, const std::string &file)
Get a writable database instance.
virtual std::string get_writable_database_path_again()
Get the path of the last opened WritableDatabase.
An indexed database of documents.
Definition: database.h:75
This class provides read/write access to a database.
Definition: database.h:964
static mt19937 gen
Definition: soaktest.cc:36
Definition: header.h:215
Public interfaces for the Xapian library.