xapian-core  1.4.26
glass_synonym.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005,2007,2008,2009,2011,2014,2016 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef XAPIAN_INCLUDED_GLASS_SYNONYM_H
22 #define XAPIAN_INCLUDED_GLASS_SYNONYM_H
23 
24 #include <xapian/types.h>
25 
26 #include "backends/alltermslist.h"
27 #include "backends/database.h"
28 #include "glass_lazytable.h"
29 #include "api/termlist.h"
30 
31 #include <set>
32 #include <string>
33 
34 namespace Glass {
35  class RootInfo;
36 }
37 using Glass::RootInfo;
38 
41  mutable std::string last_term;
42 
44  mutable std::set<std::string> last_synonyms;
45 
46  public:
55  GlassSynonymTable(const std::string & dbdir, bool readonly)
56  : GlassLazyTable("synonym", dbdir + "/synonym.", readonly) { }
57 
58  GlassSynonymTable(int fd, off_t offset_, bool readonly)
59  : GlassLazyTable("synonym", fd, offset_, readonly) { }
60 
61  // Merge in batched-up changes.
62  void merge_changes();
63 
64  // Discard batched-up changes.
65  void discard_changes() {
66  last_term.resize(0);
67  last_synonyms.clear();
68  }
69 
74  void add_synonym(const std::string & term, const std::string & synonym);
75 
80  void remove_synonym(const std::string & term, const std::string & synonym);
81 
86  void clear_synonyms(const std::string & term);
87 
92  TermList * open_termlist(const std::string & term);
93 
101  bool is_modified() const {
102  return !last_term.empty() || GlassTable::is_modified();
103  }
104 
105  void flush_db() {
106  merge_changes();
108  }
109 
110  void cancel(const RootInfo & root_info, glass_revision_number_t rev) {
111  discard_changes();
112  GlassTable::cancel(root_info, rev);
113  }
114 
115  // @}
116 };
117 
118 class GlassCursor;
119 
123 
125  void operator=(const GlassSynonymTermList &);
126 
129 
134 
136  string prefix;
137 
138  public:
140  GlassCursor * cursor_,
141  const string & prefix_)
142  : database(database_), cursor(cursor_), prefix(prefix_)
143  {
144  // Position the cursor on the highest key before the first key we want,
145  // so that the first call to next() will put us on the first key we
146  // want.
147  if (prefix.empty()) {
148  cursor->find_entry(string());
149  } else {
150  // Seek to the first key before one with the desired prefix.
151  cursor->find_entry_lt(prefix);
152  }
153  }
154 
157 
163  string get_termname() const;
164 
166  Xapian::doccount get_termfreq() const;
167 
169  TermList * next();
170 
172  TermList * skip_to(const string &tname);
173 
175  bool at_end() const;
176 };
177 
178 #endif // XAPIAN_INCLUDED_GLASS_SYNONYM_H
typedefs for Xapian
GlassSynonymTermList(Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database_, GlassCursor *cursor_, const string &prefix_)
XAPIAN_REVISION_TYPE rev
Revision number of a database.
Definition: types.h:133
void find_entry_lt(const string &key)
Position the cursor on the highest entry with key < key.
uint4 glass_revision_number_t
The revision number of a glass database.
Definition: glass_defs.h:68
Subclass of GlassTable for deriving lazy tables from.
Abstract base class for termlists.
Definition: termlist.h:39
Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database
Keep a reference to our database to stop it being deleted.
std::set< std::string > last_synonyms
The synonyms for the last term which was updated.
Definition: glass_synonym.h:44
void flush_db()
Flush any outstanding changes to the DB file of the table.
bool is_modified() const
Determine whether the object contains uncommitted modifications.
Definition: glass_table.h:697
GlassSynonymTable(int fd, off_t offset_, bool readonly)
Definition: glass_synonym.h:58
Abstract base class for iterating all terms in a database.
GlassCursor * cursor
A cursor which runs through the synonym table reading termnames from the keys.
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: glass_cursor.h:147
void flush_db()
Override methods of GlassTable.
GlassSynonymTable(const std::string &dbdir, bool readonly)
Create a new GlassSynonymTable object.
Definition: glass_synonym.h:55
std::string last_term
The last term which was updated.
Definition: glass_synonym.h:41
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
void cancel(const RootInfo &root_info, glass_revision_number_t rev)
Override methods of GlassTable.
string prefix
The prefix to restrict the terms to.
Abstract base class for termlists.
Abstract base class for iterating all terms in a database.
Definition: alltermslist.h:27
void cancel(const RootInfo &root_info, glass_revision_number_t rev)
Cancel any outstanding changes.
bool find_entry(const string &key)
Position the cursor on the highest entry with key <= key.
bool is_modified() const
Override methods of GlassTable.