xapian-core  1.4.27
maptermlist.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002,2003,2004,2005,2006,2007,2008,2010,2011,2013 Olly Betts
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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #ifndef OM_HGUARD_MAPTERMLIST_H
24 #define OM_HGUARD_MAPTERMLIST_H
25 
26 #include "termlist.h"
27 
29 #include "backends/document.h"
30 
31 #include "omassert.h"
32 
33 using namespace std;
34 
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;
40 
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  { }
46 
47  // Gets size of termlist
49  // This method shouldn't get called on a MapTermList.
50  Assert(false);
51  return 0;
52  }
53 
54  // Gets current termname
55  string get_termname() const {
56  Assert(started);
57  Assert(!at_end());
58  return it->first;
59  }
60 
61  // Get wdf of current term
63  Assert(started);
64  Assert(!at_end());
65  return it->second.wdf;
66  }
67 
68  // Get num of docs indexed by term
70  throw Xapian::InvalidOperationError("Can't get term frequency from a document termlist which is not associated with a database.");
71  }
72 
73  const std::vector<Xapian::termpos> * get_vector_termpos() const {
74  return it->second.get_vector_termpos();
75  }
76 
78  auto p = it->second.get_vector_termpos();
80  }
81 
83  return it->second.positionlist_count();
84  }
85 
86  TermList * next() {
87  if (!started) {
88  started = true;
89  } else {
90  Assert(!at_end());
91  ++it;
92  }
93  while (it != it_end && it->second.is_deleted()) {
94  ++it;
95  }
96  return NULL;
97  }
98 
99  TermList * skip_to(const std::string & term) {
100  while (it != it_end && it->first < term) {
101  ++it;
102  }
103  started = true;
104  while (it != it_end && it->second.is_deleted()) {
105  ++it;
106  }
107  return NULL;
108  }
109 
110  // True if we're off the end of the list
111  bool at_end() const {
112  Assert(started);
113  return it == it_end;
114  }
115 };
116 
117 #endif /* OM_HGUARD_MAPTERMLIST_H */
PositionList from an InMemory DB or a Document object.
#define Assert(COND)
Definition: omassert.h:122
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
Definition: maptermlist.h:69
Xapian::PositionIterator positionlist_begin() const
Return a PositionIterator for the current position.
Definition: maptermlist.h:77
InvalidOperationError indicates the API was used in an invalid way.
Definition: error.h:283
bool started
Definition: maptermlist.h:39
Abstract base class for termlists.
Definition: termlist.h:39
STL namespace.
string get_termname() const
Return the termname at the current position.
Definition: maptermlist.h:55
#define false
Definition: header.h:9
TermList * next()
Advance the current position to the next term in the termlist.
Definition: maptermlist.h:86
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
Definition: maptermlist.h:82
TermList * skip_to(const std::string &term)
Skip forward to the specified term.
Definition: maptermlist.h:99
A position list in a inmemory database.
bool at_end() const
Return true if the current position is past the last term in this list.
Definition: maptermlist.h:111
Class for iterating over term positions.
Xapian::Document::Internal::document_terms::const_iterator it_end
Definition: maptermlist.h:38
Xapian::Document::Internal::document_terms::const_iterator it
Definition: maptermlist.h:37
const std::vector< Xapian::termpos > * get_vector_termpos() const
Get pointer to vector<termpos> if that&#39;s the internal representation.
Definition: maptermlist.h:73
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
MapTermList(const Xapian::Document::Internal::document_terms::const_iterator &it_, const Xapian::Document::Internal::document_terms::const_iterator &it_end_)
Definition: maptermlist.h:42
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Definition: maptermlist.h:48
Abstract base class for termlists.
Various assertion macros.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
Definition: maptermlist.h:62