brass_database.h
Go to the documentation of this file.
1 /* brass_database.h: C++ class definition for brass database
2  *
3  * Copyright 1999,2000,2001 BrightStation PLC
4  * Copyright 2002 Ananova Ltd
5  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2012,2013 Olly Betts
6  * Copyright 2008 Lemur Consulting Ltd
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21  * USA
22  */
23 
24 #ifndef OM_HGUARD_BRASS_DATABASE_H
25 #define OM_HGUARD_BRASS_DATABASE_H
26 
27 #include "database.h"
28 #include "brass_dbstats.h"
29 #include "brass_inverter.h"
30 #include "brass_positionlist.h"
31 #include "brass_postlist.h"
32 #include "brass_record.h"
33 #include "brass_spelling.h"
34 #include "brass_synonym.h"
35 #include "brass_termlisttable.h"
36 #include "brass_values.h"
37 #include "brass_version.h"
38 #include "../flint_lock.h"
39 #include "brass_types.h"
40 #include "valuestats.h"
41 
42 #include "noreturn.h"
43 
44 #include <map>
45 
46 class BrassTermList;
48 class RemoteConnection;
49 
54  friend class BrassWritableDatabase;
55  friend class BrassTermList;
56  friend class BrassPostList;
57  friend class BrassAllTermsList;
58  friend class BrassAllDocsPostList;
59  private:
62  std::string db_dir;
63 
66  bool readonly;
67 
73 
74  /* Make postlist_table public so that bin/xapian-check.cc can get the
75  * revision number for the open database without us having to add to
76  * change the ABI. On trunk the checking code is in the library, so
77  * this is a 1.2-only hack.
78  */
79  public:
87 
88  private:
92 
96 
99 
103 
107 
117 
120 
123  unsigned int max_changesets;
124 
127 
131  bool database_exists();
132 
136  void create_and_open_tables(unsigned int blocksize);
137 
143  void open_tables_consistent();
144 
152  void get_database_write_lock(bool creating);
153 
160 
167 
178  void set_revision_number(brass_revision_number_t new_revision);
179 
183  void reopen();
184 
187  void close();
188 
195  brass_revision_number_t new_revision,
196  const std::string & msg);
197 
206  void apply();
207 
210  void cancel();
211 
214  void send_whole_database(RemoteConnection & conn, double end_time);
215 
218  void get_changeset_revisions(const string & path,
219  brass_revision_number_t * startrev,
220  brass_revision_number_t * endrev) const;
221 
222  public:
242  BrassDatabase(const string &db_dir_, int action = XAPIAN_DB_READONLY,
243  unsigned int block_size = 0u);
244 
245  ~BrassDatabase();
246 
249  return postlist_table.cursor_get();
250  }
251 
258 
263  totlen_t get_total_length() const;
266  Xapian::doccount get_termfreq(const string & tname) const;
267  Xapian::termcount get_collection_freq(const string & tname) const;
269  std::string get_value_lower_bound(Xapian::valueno slot) const;
270  std::string get_value_upper_bound(Xapian::valueno slot) const;
273  Xapian::termcount get_wdf_upper_bound(const string & term) const;
274  bool term_exists(const string & tname) const;
275  bool has_positions() const;
276 
277  LeafPostList * open_post_list(const string & tname) const;
280 
281  PositionList * open_position_list(Xapian::docid did, const string & term) const;
283  TermList * open_allterms(const string & prefix) const;
284 
285  TermList * open_spelling_termlist(const string & word) const;
287  Xapian::doccount get_spelling_frequency(const string & word) const;
288 
289  TermList * open_synonym_termlist(const string & term) const;
290  TermList * open_synonym_keylist(const string & prefix) const;
291 
292  string get_metadata(const string & key) const;
293  TermList * open_metadata_keylist(const std::string &prefix) const;
294  void write_changesets_to_fd(int fd,
295  const string & start_revision,
296  bool need_whole_db,
297  Xapian::ReplicationInfo * info);
298  string get_revision_info() const;
299  string get_uuid() const;
301 
302  XAPIAN_NORETURN(void throw_termlist_table_close_exception() const);
303 };
304 
309 
310  mutable map<Xapian::valueno, ValueStats> value_stats;
311 
316 
319 
327 
331 
333  void flush_postlist_changes() const;
334 
336  void close();
337 
339  void apply();
340 
342 
345  void commit();
346 
348  void cancel();
349 
350  Xapian::docid add_document(const Xapian::Document & document);
352  // Stop the default implementation of delete_document(term) and
353  // replace_document(term) from being hidden. This isn't really
354  // a problem as we only try to call them through the base class
355  // (where they aren't hidden) but some compilers generate a warning
356  // about the hiding.
357 #ifndef _MSC_VER
360 #endif
361  void delete_document(Xapian::docid did);
362  void replace_document(Xapian::docid did, const Xapian::Document & document);
363 
365  bool lazy) const;
366 
368 
369  public:
381  BrassWritableDatabase(const string &dir, int action, int block_size);
382 
384 
388  Xapian::doccount get_termfreq(const string & tname) const;
389  Xapian::termcount get_collection_freq(const string & tname) const;
391  std::string get_value_lower_bound(Xapian::valueno slot) const;
392  std::string get_value_upper_bound(Xapian::valueno slot) const;
393  bool term_exists(const string & tname) const;
394 
395  LeafPostList * open_post_list(const string & tname) const;
397  TermList * open_allterms(const string & prefix) const;
398 
399  void add_spelling(const string & word, Xapian::termcount freqinc) const;
400  void remove_spelling(const string & word, Xapian::termcount freqdec) const;
402 
403  TermList * open_synonym_keylist(const string & prefix) const;
404  void add_synonym(const string & word, const string & synonym) const;
405  void remove_synonym(const string & word, const string & synonym) const;
406  void clear_synonyms(const string & word) const;
407 
408  void set_metadata(const string & key, const string & value);
411 };
412 
413 #endif /* OM_HGUARD_BRASS_DATABASE_H */

Documentation for Xapian (version 1.2.19).
Generated on Tue Oct 21 2014 by Doxygen 1.8.1.2.