Add constant FLINT_MAX_DOCID
[xapian.git] / xapian-core / api / maptermlist.h
blobbfa15715be4549776f5b48e0e107947286f39807
1 /* maptermlist.h
3 * Copyright 1999,2000,2001 BrightStation PLC
4 * Copyright 2002,2003,2004,2005,2006,2007,2008,2010 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
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.
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
19 * USA
22 #ifndef OM_HGUARD_MAPTERMLIST_H
23 #define OM_HGUARD_MAPTERMLIST_H
25 #include "termlist.h"
27 #include "inmemory_positionlist.h"
28 #include "document.h"
30 #include "omassert.h"
32 using namespace std;
34 class MapTermList : public TermList {
35 private:
36 Xapian::Document::Internal::document_terms::const_iterator it;
37 Xapian::Document::Internal::document_terms::const_iterator it_end;
38 bool started;
40 public:
41 MapTermList(const Xapian::Document::Internal::document_terms::const_iterator &it_,
42 const Xapian::Document::Internal::document_terms::const_iterator &it_end_)
43 : it(it_), it_end(it_end_), started(false)
44 { }
46 // Gets size of termlist
47 Xapian::termcount get_approx_size() const {
48 // This method shouldn't get called on a MapTermList.
49 Assert(false);
50 return 0;
53 // Gets current termname
54 string get_termname() const {
55 Assert(started);
56 Assert(!at_end());
57 return it->first;
60 // Get wdf of current term
61 Xapian::termcount get_wdf() const {
62 Assert(started);
63 Assert(!at_end());
64 return it->second.wdf;
67 // Get num of docs indexed by term
68 Xapian::doccount get_termfreq() const {
69 throw Xapian::InvalidOperationError("Can't get term frequency from a document termlist which is not associated with a database.");
72 Xapian::PositionIterator positionlist_begin() const {
73 return Xapian::PositionIterator(new InMemoryPositionList(it->second.positions));
76 Xapian::termcount positionlist_count() const {
77 return it->second.positions.size();
80 TermList * next() {
81 if (!started) {
82 started = true;
83 } else {
84 Assert(!at_end());
85 ++it;
87 return NULL;
90 TermList * skip_to(const std::string & term) {
91 while (it != it_end && it->first < term) {
92 ++it;
94 started = true;
95 return NULL;
98 // True if we're off the end of the list
99 bool at_end() const {
100 Assert(started);
101 return it == it_end;
105 #endif /* OM_HGUARD_MAPTERMLIST_H */