xapian-core  1.4.26
chert_synonym.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005,2007,2008,2009,2011 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_CHERT_SYNONYM_H
22 #define XAPIAN_INCLUDED_CHERT_SYNONYM_H
23 
24 #include <xapian/types.h>
25 
26 #include "backends/alltermslist.h"
27 #include "backends/database.h"
28 #include "chert_lazytable.h"
29 #include "api/termlist.h"
30 
31 #include <set>
32 #include <string>
33 
36  mutable std::string last_term;
37 
39  mutable std::set<std::string> last_synonyms;
40 
41  public:
50  ChertSynonymTable(const std::string & dbdir, bool readonly)
51  : ChertLazyTable("synonym", dbdir + "/synonym.", readonly,
52  Z_DEFAULT_STRATEGY) { }
53 
54  // Merge in batched-up changes.
55  void merge_changes();
56 
57  // Discard batched-up changes.
58  void discard_changes() {
59  last_term.resize(0);
60  last_synonyms.clear();
61  }
62 
67  void add_synonym(const std::string & term, const std::string & synonym);
68 
73  void remove_synonym(const std::string & term, const std::string & synonym);
74 
79  void clear_synonyms(const std::string & term);
80 
85  TermList * open_termlist(const std::string & term);
86 
94  bool is_modified() const {
95  return !last_term.empty() || ChertTable::is_modified();
96  }
97 
98  void flush_db() {
99  merge_changes();
101  }
102 
103  void cancel() {
104  discard_changes();
106  }
107 
108  // @}
109 };
110 
111 class ChertCursor;
112 
116 
118  void operator=(const ChertSynonymTermList &);
119 
122 
127 
129  string prefix;
130 
131  public:
133  ChertCursor * cursor_,
134  const string & prefix_)
135  : database(database_), cursor(cursor_), prefix(prefix_)
136  {
137  // Position the cursor on the highest key before the first key we want,
138  // so that the first call to next() will put us on the first key we
139  // want.
140  if (prefix.empty()) {
141  cursor->find_entry(string());
142  } else {
143  // Seek to the first key before one with the desired prefix.
144  cursor->find_entry_lt(prefix);
145  }
146  }
147 
150 
156  string get_termname() const;
157 
159  Xapian::doccount get_termfreq() const;
160 
162  TermList * next();
163 
165  TermList * skip_to(const string &tname);
166 
168  bool at_end() const;
169 };
170 
171 #endif // XAPIAN_INCLUDED_CHERT_SYNONYM_H
bool is_modified() const
Override methods of ChertTable.
Definition: chert_synonym.h:94
ChertCursor * cursor
A cursor which runs through the synonym table reading termnames from the keys.
ChertSynonymTermList(Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database_, ChertCursor *cursor_, const string &prefix_)
typedefs for Xapian
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: chert_cursor.h:66
void clear_synonyms(const std::string &term)
Remove all synonyms for term.
std::string last_term
The last term which was updated.
Definition: chert_synonym.h:36
std::set< std::string > last_synonyms
The synonyms for the last term which was updated.
Definition: chert_synonym.h:39
Abstract base class for termlists.
Definition: termlist.h:39
string prefix
The prefix to restrict the terms to.
TermList * open_termlist(const std::string &term)
Open synonym termlist for a term.
void add_synonym(const std::string &term, const std::string &synonym)
Add a synonym for term.
void cancel()
Cancel any outstanding changes.
bool is_modified() const
Determine whether the object contains uncommitted modifications.
Definition: chert_table.h:653
bool next(Cursor *C_, int j) const
Definition: chert_table.h:821
void flush_db()
Override methods of ChertTable.
Definition: chert_synonym.h:98
Abstract base class for iterating all terms in a database.
ChertTable & operator=(const ChertTable &)
Assignment not allowed.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Subclass of ChertTable for deriving lazy tables from.
void find_entry_lt(const string &key)
Position the cursor on the highest entry with key < key.
Definition: chert_cursor.h:218
ChertSynonymTable(const std::string &dbdir, bool readonly)
Create a new ChertSynonymTable object.
Definition: chert_synonym.h:50
Abstract base class for termlists.
Xapian::Internal::intrusive_ptr< const Xapian::Database::Internal > database
Keep a reference to our database to stop it being deleted.
void flush_db()
Flush any outstanding changes to the DB file of the table.
Abstract base class for iterating all terms in a database.
Definition: alltermslist.h:27
void cancel()
Override methods of ChertTable.
bool find_entry(const string &key)
Position the cursor on the highest entry with key <= key.
void remove_synonym(const std::string &term, const std::string &synonym)
Remove a synonym for term.