xapian-core  1.4.26
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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #ifndef OM_HGUARD_BACKENDMANAGER_H
24 #define OM_HGUARD_BACKENDMANAGER_H
25 
26 #include <xapian.h>
27 #include <vector>
28 
29 // Paths to xapian-tcpsrv and xapian-progsrv.
30 #ifdef __WIN32__
31 // Under __WIN32__ we want \ path separators since we pass this path to
32 // CreateProcess().
33 # define XAPIAN_BIN_PATH "..\\bin\\"
34 # define EXE_SUFFIX ".exe"
35 #else
36 # define XAPIAN_BIN_PATH "../bin/"
37 # define EXE_SUFFIX
38 #endif
39 #define XAPIAN_TCPSRV XAPIAN_BIN_PATH "xapian-tcpsrv" EXE_SUFFIX
40 #define XAPIAN_PROGSRV XAPIAN_BIN_PATH "xapian-progsrv" EXE_SUFFIX
41 
44  std::string datadir;
45 
47  std::string dbtype;
48 
49  protected:
52  const std::vector<std::string> & files);
53 
54  bool create_dir_if_needed(const std::string &dirname);
55 
62  virtual Xapian::Database do_get_database(const std::vector<std::string> &files);
63 
70  virtual std::string do_get_database_path(const std::vector<std::string> &files);
71 
72  public:
74  BackendManager(const std::string& datadir_, const std::string& dbtype_)
75  : datadir(datadir_), dbtype(dbtype_) {}
76 
80  virtual ~BackendManager();
81 
84  const std::string& get_dbtype() const { return dbtype; }
85 
88  const std::string & get_datadir() const { return datadir; }
89 
91  Xapian::Database get_database(const std::vector<std::string> &files);
92 
94  Xapian::Database get_database(const std::string &file);
95 
105  Xapian::Database get_database(const std::string &dbname,
106  void (*gen)(Xapian::WritableDatabase&,
107  const std::string &),
108  const std::string &arg);
109 
111  virtual Xapian::Database get_database_by_path(const std::string& path);
112 
114  std::string get_database_path(const std::vector<std::string> &files);
115 
117  std::string get_database_path(const std::string &file);
118 
120  std::string get_database_path(const std::string &dbname,
121  void (*gen)(Xapian::WritableDatabase&,
122  const std::string &),
123  const std::string &arg);
124 
126  virtual Xapian::WritableDatabase get_writable_database(const std::string & name, const std::string & file);
127 
130  get_remote_writable_database(std::string args);
131 
133  virtual std::string get_writable_database_path(const std::string & name);
134 
137  get_generated_database(const std::string& name);
138 
140  virtual std::string get_generated_database_path(const std::string & name);
141 
143  virtual void finalise_generated_database(const std::string& name);
144 
146  virtual Xapian::Database get_remote_database(const std::vector<std::string> & files, unsigned int timeout);
147 
151  virtual std::string get_writable_database_args(const std::string& path,
152  unsigned int timeout);
153 
156 
159 
161  virtual std::string get_writable_database_path_again();
162 
164  virtual std::string get_compaction_output_path(const std::string& name);
165 
170  virtual void clean_up();
171 
173  static const char * get_xapian_progsrv_command();
174 };
175 
176 #endif /* OM_HGUARD_BACKENDMANAGER_H */
static const char * get_xapian_progsrv_command()
Get the command line required to run xapian-progsrv.
const std::string & get_datadir() const
Get the directory to store data in.
virtual Xapian::Database get_remote_database(const std::vector< std::string > &files, unsigned int timeout)
Get a remote database instance with the specified timeout.
std::string datadir
The current data directory.
BackendManager(const std::string &datadir_, const std::string &dbtype_)
Constructor.
const std::string & get_dbtype() const
Get the database type currently in use.
This class is used to access a database, or a group of databases.
Definition: database.h:68
unsigned timeout
A timeout value in milliseconds.
Definition: types.h:100
Xapian::Database get_database(const std::vector< std::string > &files)
Get a database instance of the current type.
virtual std::string get_generated_database_path(const std::string &name)
Get the path to use for generating a database, if supported.
std::string get_database_path(const std::vector< std::string > &files)
Get the path of a database instance, if such a thing exists.
virtual Xapian::WritableDatabase get_generated_database(const std::string &name)
Get a generated writable database instance.
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 Xapian::WritableDatabase get_writable_database(const std::string &name, const std::string &file)
Get a writable database instance.
std::string dbtype
The backend database type (set by subclass ctor).
bool create_dir_if_needed(const std::string &dirname)
Create the directory dirname if needed.
virtual Xapian::WritableDatabase get_writable_database_again()
Create a WritableDatabase object for the last opened WritableDatabase.
virtual Xapian::Database get_database_by_path(const std::string &path)
Get a database instance by path.
This class provides read/write access to a database.
Definition: database.h:789
Public interfaces for the Xapian library.
virtual Xapian::WritableDatabase get_remote_writable_database(std::string args)
Get a remote Xapian::WritableDatabase instance with specified args.
virtual std::string get_writable_database_path_again()
Get the path of the last opened WritableDatabase.
virtual void clean_up()
Called after each test, to perform any necessary cleanup.
static mt19937 gen
Definition: soaktest.cc:37
virtual ~BackendManager()
We have virtual methods and want to be able to delete derived classes using a pointer to the base cla...
virtual Xapian::Database do_get_database(const std::vector< std::string > &files)
Virtual method implementing get_database().
virtual std::string do_get_database_path(const std::vector< std::string > &files)
Virtual method implementing get_database_path().
virtual Xapian::Database get_writable_database_as_database()
Create a Database object for the last opened WritableDatabase.
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.
Definition: header.h:151
virtual std::string get_compaction_output_path(const std::string &name)
Get a path to compact a database to.
virtual void finalise_generated_database(const std::string &name)
Finalise the generated 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.