Document xapian-compact --blocksize takes an argument
[xapian.git] / xapian-core / api / maptermlist.h
blobed452f5ecfb5f0d551929048d2be9e4c94275615
1 /** @file maptermlist.h
2 * @brief TermList which iterates a std::map.
3 */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002,2003,2004,2005,2006,2007,2008,2010,2011,2013 Olly Betts
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.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
23 #ifndef OM_HGUARD_MAPTERMLIST_H
24 #define OM_HGUARD_MAPTERMLIST_H
26 #include "termlist.h"
28 #include "backends/inmemory/inmemory_positionlist.h"
29 #include "backends/document.h"
31 #include "omassert.h"
33 using namespace std;
35 class MapTermList : public TermList {
36 private:
37 Xapian::Document::Internal::document_terms::const_iterator it;
38 Xapian::Document::Internal::document_terms::const_iterator it_end;
39 bool started;
41 public:
42 MapTermList(const Xapian::Document::Internal::document_terms::const_iterator &it_,
43 const Xapian::Document::Internal::document_terms::const_iterator &it_end_)
44 : it(it_), it_end(it_end_), started(false)
45 { }
47 // Gets size of termlist
48 Xapian::termcount get_approx_size() const {
49 // This method shouldn't get called on a MapTermList.
50 Assert(false);
51 return 0;
54 // Gets current termname
55 string get_termname() const {
56 Assert(started);
57 Assert(!at_end());
58 return it->first;
61 // Get wdf of current term
62 Xapian::termcount get_wdf() const {
63 Assert(started);
64 Assert(!at_end());
65 return it->second.wdf;
68 // Get num of docs indexed by term
69 Xapian::doccount get_termfreq() const {
70 throw Xapian::InvalidOperationError("Can't get term frequency from a document termlist which is not associated with a database.");
73 const std::vector<Xapian::termpos> * get_vector_termpos() const {
74 return &(it->second.positions);
77 Xapian::PositionIterator positionlist_begin() const {
78 return Xapian::PositionIterator(new InMemoryPositionList(it->second.positions));
81 Xapian::termcount positionlist_count() const {
82 return it->second.positions.size();
85 TermList * next() {
86 if (!started) {
87 started = true;
88 } else {
89 Assert(!at_end());
90 ++it;
92 return NULL;
95 TermList * skip_to(const std::string & term) {
96 while (it != it_end && it->first < term) {
97 ++it;
99 started = true;
100 return NULL;
103 // True if we're off the end of the list
104 bool at_end() const {
105 Assert(started);
106 return it == it_end;
110 #endif /* OM_HGUARD_MAPTERMLIST_H */