xapian-core  2.0.0
keymaker.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2009,2011,2013,2014,2015,2016,2019,2024 Olly Betts
5  * Copyright (C) 2010 Richard Boulton
6  *
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.
11  *
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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_KEYMAKER_H
23 #define XAPIAN_INCLUDED_KEYMAKER_H
24 
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error Never use <xapian/keymaker.h> directly; include <xapian.h> instead.
27 #endif
28 
29 #include <string>
30 #include <string_view>
31 #include <vector>
32 
33 #include <xapian/intrusive_ptr.h>
34 #include <xapian/types.h>
35 #include <xapian/visibility.h>
36 
37 namespace Xapian {
38 
39 class Document;
40 class Registry;
41 
46  void operator=(const KeyMaker &) = delete;
47 
49  KeyMaker(const KeyMaker &) = delete;
50 
51  public:
53  KeyMaker() { }
54 
61  virtual std::string operator()(const Xapian::Document & doc) const = 0;
62 
64  virtual ~KeyMaker();
65 
80  virtual std::string name() const;
81 
90  virtual std::string serialise() const;
91 
113  virtual KeyMaker* unserialise(const std::string& serialised,
114  const Registry& context) const;
115 
124  opt_intrusive_base::release();
125  return this;
126  }
127 
135  const KeyMaker * release() const {
136  opt_intrusive_base::release();
137  return this;
138  }
139 };
140 
157  struct KeySpec {
159  bool reverse;
160  std::string defvalue;
161  KeySpec(Xapian::valueno slot_, bool reverse_,
162  std::string_view defvalue_)
163  : slot(slot_), reverse(reverse_), defvalue(defvalue_)
164  {}
165  };
166  std::vector<KeySpec> slots;
167 
168  public:
170 
176  template<class Iterator>
177  MultiValueKeyMaker(Iterator begin, Iterator end) {
178  while (begin != end) add_value(*begin++);
179  }
180 
181  virtual std::string operator()(const Xapian::Document & doc) const;
182 
195  void add_value(Xapian::valueno slot, bool reverse = false,
196  std::string_view defvalue = {}) {
197  slots.push_back(KeySpec(slot, reverse, defvalue));
198  }
199 
200  std::string name() const;
201 
202  std::string serialise() const;
203 
204  KeyMaker* unserialise(const std::string& serialised,
205  const Registry& context) const;
206 };
207 
208 }
209 
210 #endif // XAPIAN_INCLUDED_KEYMAKER_H
char name[9]
Definition: dbcheck.cc:57
Class representing a document.
Definition: document.h:64
Base class for objects managed by opt_intrusive_ptr.
Virtual base class for key making functors.
Definition: keymaker.h:44
const KeyMaker * release() const
Start reference counting this object.
Definition: keymaker.h:135
KeyMaker()
Default constructor.
Definition: keymaker.h:53
KeyMaker(const KeyMaker &)=delete
Don't allow copying.
void operator=(const KeyMaker &)=delete
Don't allow assignment.
virtual std::string operator()(const Xapian::Document &doc) const =0
Build a key string for a Document.
KeyMaker * release()
Start reference counting this object.
Definition: keymaker.h:123
KeyMaker subclass which combines several values.
Definition: keymaker.h:156
void add_value(Xapian::valueno slot, bool reverse=false, std::string_view defvalue={})
Add a value slot to the list to build a key from.
Definition: keymaker.h:195
MultiValueKeyMaker(Iterator begin, Iterator end)
Construct a MultiValueKeyMaker from a pair of iterators.
Definition: keymaker.h:177
std::vector< KeySpec > slots
Definition: keymaker.h:166
Registry for user subclasses.
Definition: registry.h:47
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90
KeySpec(Xapian::valueno slot_, bool reverse_, std::string_view defvalue_)
Definition: keymaker.h:161
typedefs for Xapian
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28