xapian-core  2.0.0
honey_synonym.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005,2007,2008,2009,2011,2014,2016,2017,2024 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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_HONEY_SYNONYM_H
22 #define XAPIAN_INCLUDED_HONEY_SYNONYM_H
23 
24 #include <xapian/types.h>
25 
26 #include "api/termlist.h"
27 #include "backends/alltermslist.h"
28 #include "honey_cursor.h"
29 #include "honey_lazytable.h"
30 
31 #include <functional>
32 #include <set>
33 #include <string>
34 #include <string_view>
35 
36 class HoneyDatabase;
37 
38 namespace Honey {
39  class RootInfo;
40 }
41 
44  mutable std::string last_term;
45 
47  mutable std::set<std::string, std::less<>> last_synonyms;
48 
49  public:
58  HoneySynonymTable(const std::string& dbdir, bool readonly)
59  : HoneyLazyTable("synonym", dbdir + "/synonym.", readonly) { }
60 
61  HoneySynonymTable(int fd, off_t offset_, bool readonly)
62  : HoneyLazyTable("synonym", fd, offset_, readonly) { }
63 
64  // Merge in batched-up changes.
65  void merge_changes();
66 
67  // Discard batched-up changes.
68  void discard_changes() {
69  last_term.resize(0);
70  last_synonyms.clear();
71  }
72 
77  void add_synonym(std::string_view term, std::string_view synonym);
78 
83  void remove_synonym(std::string_view term, std::string_view synonym);
84 
89  void clear_synonyms(std::string_view term);
90 
95  TermList* open_termlist(std::string_view term) const;
96 
104  bool is_modified() const {
105  return !last_term.empty() || HoneyTable::is_modified();
106  }
107 
108  void flush_db() {
109  merge_changes();
111  }
112 
113  void cancel(const Honey::RootInfo& root_info,
115  discard_changes();
116  HoneyTable::cancel(root_info, rev);
117  }
118 
119  // @}
120 };
121 
122 class HoneyCursor;
123 
127 
130 
133 
138 
140  std::string prefix;
141 
142  public:
144  HoneyCursor* cursor_,
145  std::string_view prefix_)
146  : database(database_), cursor(cursor_), prefix(prefix_)
147  {
148  // Set the cursor to its end to signal we haven't started yet.
149  cursor->to_end();
150  }
151 
154 
156 
159 
161  TermList* next();
162 
164  TermList* skip_to(std::string_view term);
165 };
166 
167 #endif // XAPIAN_INCLUDED_HONEY_SYNONYM_H
Abstract base class for iterating all terms in a database.
Abstract base class for iterating all terms in a database.
Definition: alltermslist.h:27
void to_end()
Definition: honey_cursor.h:92
Database using honey backend.
std::set< std::string, std::less<> > last_synonyms
The synonyms for the last term which was updated.
Definition: honey_synonym.h:47
bool is_modified() const
Override methods of HoneyTable.
void clear_synonyms(std::string_view term)
Remove all synonyms for term.
void flush_db()
Override methods of HoneyTable.
HoneySynonymTable(int fd, off_t offset_, bool readonly)
Definition: honey_synonym.h:61
void add_synonym(std::string_view term, std::string_view synonym)
Add a synonym for term.
void cancel(const Honey::RootInfo &root_info, honey_revision_number_t rev)
Override methods of HoneyTable.
void remove_synonym(std::string_view term, std::string_view synonym)
Remove a synonym for term.
std::string last_term
The last term which was updated.
Definition: honey_synonym.h:44
TermList * open_termlist(std::string_view term) const
Open synonym termlist for a term.
HoneySynonymTable(const std::string &dbdir, bool readonly)
Create a new HoneySynonymTable object.
Definition: honey_synonym.h:58
TermList * skip_to(std::string_view term)
Advance to the first term which is >= term.
HoneySynonymTermList(const HoneyDatabase *database_, HoneyCursor *cursor_, std::string_view prefix_)
HoneySynonymTermList(const HoneySynonymTermList &)
Copying is not allowed.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
void operator=(const HoneySynonymTermList &)
Assignment is not allowed.
HoneyCursor * cursor
A cursor which runs through the synonym table reading termnames from the keys.
~HoneySynonymTermList()
Destructor.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
TermList * next()
Advance to the next term in the list.
std::string prefix
The prefix to restrict the terms to.
Xapian::Internal::intrusive_ptr< const HoneyDatabase > database
Keep a reference to our database to stop it being deleted.
void cancel(const Honey::RootInfo &, honey_revision_number_t)
Definition: honey_table.h:648
bool is_modified() const
Definition: honey_table.h:678
void flush_db()
Definition: honey_table.h:643
Abstract base class for termlists.
Definition: termlist.h:42
string term
HoneyCursor class.
uint4 honey_revision_number_t
The revision number of a honey database.
Definition: honey_defs.h:104
Subclass of HoneyTable for deriving lazy tables from.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
XAPIAN_REVISION_TYPE rev
Revision number of a database.
Definition: types.h:108
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
Abstract base class for termlists.
typedefs for Xapian