generate-exceptions,include/xapian/: Remove XAPIAN_PURE_FUNCTION
[xapian.git] / xapian-core / include / xapian / compactor.h
blobf03859bbccc0694581305480a5ff317091db1d7f
1 /** @file compactor.h
2 * @brief Compact a database, or merge and compact several.
3 */
4 /* Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010,2011,2013,2014 Olly Betts
5 * Copyright (C) 2008 Lemur Consulting Ltd
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.
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.
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
23 #ifndef XAPIAN_INCLUDED_COMPACTOR_H
24 #define XAPIAN_INCLUDED_COMPACTOR_H
26 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
27 # error "Never use <xapian/compactor.h> directly; include <xapian.h> instead."
28 #endif
30 #include <xapian/intrusive_ptr.h>
31 #include <xapian/visibility.h>
32 #include <string>
34 namespace Xapian {
36 /** Compact a database, or merge and compact several.
38 class XAPIAN_VISIBILITY_DEFAULT Compactor {
39 public:
40 /// Class containing the implementation.
41 class Internal;
43 typedef enum { STANDARD, FULL, FULLER } compaction_level;
45 private:
46 /// @internal Reference counted internals.
47 Xapian::Internal::intrusive_ptr<Internal> internal;
49 public:
50 Compactor();
52 virtual ~Compactor();
54 /** Set the block size to use for tables in the output database.
56 * @param block_size The block size to use. Valid block sizes are
57 * currently powers of two between 2048 and 65536,
58 * with the default being 8192, but the valid
59 * sizes and default may change in the future.
61 void set_block_size(size_t block_size);
63 /** Set whether to preserve existing document id values.
65 * @param renumber The default is true, which means that document ids will
66 * be renumbered - currently by applying the same offset
67 * to all the document ids in a particular source
68 * database.
70 * If false, then the document ids must be unique over all
71 * source databases. Currently the ranges of document ids
72 * in each source must not overlap either, though this
73 * restriction may be removed in the future.
75 void set_renumber(bool renumber);
77 /** Set whether to merge postlists in multiple passes.
79 * @param multipass If true and merging more than 3 databases,
80 * merge the postlists in multiple passes, which is generally faster but
81 * requires more disk space for temporary files. By default we don't do
82 * this.
84 void set_multipass(bool multipass);
86 /** Set the compaction level.
88 * @param compaction Available values are:
89 * - Xapian::Compactor::STANDARD - Don't split items unnecessarily.
90 * - Xapian::Compactor::FULL - Split items whenever it saves space
91 * (the default).
92 * - Xapian::Compactor::FULLER - Allow oversize items to save more space
93 * (not recommended if you ever plan to update the compacted database).
95 void set_compaction_level(compaction_level compaction);
97 /** Set where to write the output.
99 * @param destdir Output path. This can be the same as an input if that
100 * input is a stub database (in which case the database(s)
101 * listed in the stub will be compacted to a new database
102 * and then the stub will be atomically updated to point
103 * to this new database).
105 void set_destdir(const std::string & destdir);
107 /** Add a source database.
109 * @param srcdir The path to the source database to add.
111 void add_source(const std::string & srcdir);
113 /// Perform the actual compaction/merging operation.
114 void compact();
116 /** Update progress.
118 * Subclass this method if you want to get progress updates during
119 * compaction. This is called for each table first with empty status,
120 * And then one or more times with non-empty status.
122 * The default implementation does nothing.
124 * @param table The table currently being compacted.
125 * @param status A status message.
127 virtual void
128 set_status(const std::string & table, const std::string & status);
130 /** Resolve multiple user metadata entries with the same key.
132 * When merging, if the same user metadata key is set in more than one
133 * input, then this method is called to allow this to be resolving in
134 * an appropriate way.
136 * The default implementation just returns tags[0].
138 * For multipass this will currently get called multiple times for the
139 * same key if there are duplicates to resolve in each pass, but this
140 * may change in the future.
142 * @param key The metadata key with duplicate entries.
143 * @param num_tags How many tags there are.
144 * @param tags An array of num_tags strings containing the tags to
145 * merge.
147 virtual std::string
148 resolve_duplicate_metadata(const std::string & key,
149 size_t num_tags, const std::string tags[]);
154 #endif /* XAPIAN_INCLUDED_COMPACTOR_H */