TermList::positionlist_begin() now returns PositionList*
[xapian.git] / xapian-core / api / documenttermlist.cc
blob4723ed1c20ddb7e5489fbfce551d9968395af29f
1 /** @file documenttermlist.cc
2 * @brief Iteration over terms in a document
3 */
4 /* Copyright 2017 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 USA
21 #include <config.h>
23 #include "documenttermlist.h"
25 #include "backends/inmemory/inmemory_positionlist.h"
26 #include "omassert.h"
28 #include "xapian/error.h"
30 using namespace std;
32 Xapian::termcount
33 DocumentTermList::get_approx_size() const
35 // DocumentTermList is only used in a TermIterator wrapper and that never
36 // calls this method.
37 Assert(false);
38 return 0;
41 string
42 DocumentTermList::get_termname() const
44 Assert(!at_end());
45 return it->first;
48 Xapian::termcount
49 DocumentTermList::get_wdf() const
51 Assert(!at_end());
52 return it->second.get_wdf();
55 Xapian::doccount
56 DocumentTermList::get_termfreq() const
58 throw Xapian::InvalidOperationError("get_termfreq() not valid for a TermIterator from a Document which is not associated with a database");
61 const Xapian::VecCOW<Xapian::termpos>*
62 DocumentTermList::get_vec_termpos() const
64 return it->second.get_positions();
67 PositionList*
68 DocumentTermList::positionlist_begin() const
70 return new InMemoryPositionList(*it->second.get_positions());
73 Xapian::termcount
74 DocumentTermList::positionlist_count() const
76 return it->second.get_positions()->size();
79 TermList*
80 DocumentTermList::next()
82 if (it == doc->terms->end()) {
83 it = doc->terms->begin();
84 } else {
85 ++it;
87 while (it != doc->terms->end() && it->second.is_deleted()) {
88 ++it;
90 return NULL;
93 TermList*
94 DocumentTermList::skip_to(const string& term)
96 it = doc->terms->lower_bound(term);
97 while (it != doc->terms->end() && it->second.is_deleted()) {
98 ++it;
100 return NULL;
103 bool
104 DocumentTermList::at_end() const
106 return it == doc->terms->end();