xapian-core  1.4.27
matchspy.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2009,2010,2011,2012,2013,2014,2015 Olly Betts
5  * Copyright (C) 2007,2009 Lemur Consulting Ltd
6  * Copyright (C) 2010 Richard Boulton
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (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 USA
21  */
22 
23 #ifndef XAPIAN_INCLUDED_MATCHSPY_H
24 #define XAPIAN_INCLUDED_MATCHSPY_H
25 
26 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
27 # error Never use <xapian/matchspy.h> directly; include <xapian.h> instead.
28 #endif
29 
30 #include <xapian/attributes.h>
31 #include <xapian/intrusive_ptr.h>
32 #include <xapian/termiterator.h>
33 #include <xapian/visibility.h>
34 
35 #include <string>
36 #include <map>
37 
38 namespace Xapian {
39 
40 class Document;
41 class Registry;
42 
51  private:
53  void operator=(const MatchSpy &);
54 
56  MatchSpy(const MatchSpy &);
57 
58  public:
60  XAPIAN_NOTHROW(MatchSpy()) {}
61 
63  virtual ~MatchSpy();
64 
76  virtual void operator()(const Xapian::Document &doc,
77  double wt) = 0;
78 
96  virtual MatchSpy * clone() const;
97 
112  virtual std::string name() const;
113 
120  virtual std::string serialise() const;
121 
143  virtual MatchSpy * unserialise(const std::string & serialised,
144  const Registry & context) const;
145 
152  virtual std::string serialise_results() const;
153 
166  virtual void merge_results(const std::string & serialised);
167 
175  virtual std::string get_description() const;
176 
185  opt_intrusive_base::release();
186  return this;
187  }
188 
196  const MatchSpy * release() const {
197  opt_intrusive_base::release();
198  return this;
199  }
200 };
201 
202 
206  public:
207  struct Internal;
208 
209 #ifndef SWIG // SWIG doesn't need to know about the internal class
210  struct XAPIAN_VISIBILITY_DEFAULT Internal
213  {
216 
219 
221  std::map<std::string, Xapian::doccount> values;
222 
223  Internal() : slot(Xapian::BAD_VALUENO), total(0) {}
224  explicit Internal(Xapian::valueno slot_) : slot(slot_), total(0) {}
225  };
226 #endif
227 
228  protected:
231 
232  public:
235 
238  : internal(new Internal(slot_)) {}
239 
241  size_t XAPIAN_NOTHROW(get_total() const) {
242  return internal.get() ? internal->total : 0;
243  }
244 
252  TermIterator values_begin() const;
253 
255  TermIterator XAPIAN_NOTHROW(values_end() const) {
256  return TermIterator();
257  }
258 
269  TermIterator top_values_begin(size_t maxvalues) const;
270 
272  TermIterator XAPIAN_NOTHROW(top_values_end(size_t) const) {
273  return TermIterator();
274  }
275 
283  void operator()(const Xapian::Document &doc, double wt);
284 
285  virtual MatchSpy * clone() const;
286  virtual std::string name() const;
287  virtual std::string serialise() const;
288  virtual MatchSpy * unserialise(const std::string & serialised,
289  const Registry & context) const;
290  virtual std::string serialise_results() const;
291  virtual void merge_results(const std::string & serialised);
292  virtual std::string get_description() const;
293 };
294 
295 }
296 
297 #endif // XAPIAN_INCLUDED_MATCHSPY_H
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
TermIterator values_end() const
End iterator corresponding to values_begin()
Definition: matchspy.h:255
MatchSpy * release()
Start reference counting this object.
Definition: matchspy.h:184
Abstract base class for match spies.
Definition: matchspy.h:49
Compiler attribute macros.
size_t get_total() const
Return the total number of documents tallied.
Definition: matchspy.h:241
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
Xapian::valueno slot
The slot to count.
Definition: matchspy.h:215
MatchSpy()
Default constructor, needed by subclass constructors.
Definition: matchspy.h:60
Class for iterating over a list of terms.
Definition: termiterator.h:41
std::map< std::string, Xapian::doccount > values
The values seen so far, together with their frequency.
Definition: matchspy.h:221
Define XAPIAN_VISIBILITY_* macros.
Registry for user subclasses.
Definition: registry.h:47
ValueCountMatchSpy(Xapian::valueno slot_)
Construct a MatchSpy which counts the values in a particular slot.
Definition: matchspy.h:237
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:49
Base class for objects managed by opt_intrusive_ptr.
TermIterator top_values_end(size_t) const
End iterator corresponding to top_values_begin()
Definition: matchspy.h:272
Xapian::doccount total
Total number of documents seen by the match spy.
Definition: matchspy.h:218
Class for counting the frequencies of values in the matching documents.
Definition: matchspy.h:205
Internal(Xapian::valueno slot_)
Definition: matchspy.h:224
char name[9]
Definition: dbcheck.cc:55
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
ValueCountMatchSpy()
Construct an empty ValueCountMatchSpy.
Definition: matchspy.h:234
const valueno BAD_VALUENO
Reserved value to indicate "no valueno".
Definition: types.h:125
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:81
Class for iterating over a list of terms.
A handle representing a document in a Xapian database.
Definition: document.h:61
const MatchSpy * release() const
Start reference counting this object.
Definition: matchspy.h:196