Implement TermIterator::positionlist_count() for remote backend
[xapian.git] / xapian-core / backends / remote / net_termlist.cc
blobb540331b3cd40717938600a8da62aeb7b59515e3
1 /* net_termlist.cc
3 * Copyright 1999,2000,2001 BrightStation PLC
4 * Copyright 2002,2003,2006,2007,2008,2009,2010,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
19 * USA
22 #include <config.h>
24 #include "net_termlist.h"
26 #include "omassert.h"
28 #include <xapian/error.h>
30 using Xapian::Internal::intrusive_ptr;
32 NetworkTermList::NetworkTermList(Xapian::termcount document_length_,
33 Xapian::doccount database_size_,
34 intrusive_ptr<const RemoteDatabase> this_db_,
35 Xapian::docid did_)
36 : items(),
37 current_position(items.begin()),
38 started(false),
39 document_length(document_length_),
40 database_size(database_size_),
41 this_db(this_db_),
42 did(did_)
46 Xapian::termcount
47 NetworkTermList::get_approx_size() const
49 return items.size();
52 void
53 NetworkTermList::accumulate_stats(Xapian::Internal::ExpandStats & stats) const
55 Assert(started);
56 Assert(!at_end());
58 stats.accumulate(current_position->wdf,
59 document_length,
60 current_position->termfreq,
61 database_size);
64 string
65 NetworkTermList::get_termname() const
67 Assert(started);
68 Assert(!at_end());
69 return current_position->tname;
72 Xapian::termcount
73 NetworkTermList::get_wdf() const
75 Assert(started);
76 Assert(!at_end());
77 return current_position->wdf;
80 Xapian::doccount
81 NetworkTermList::get_termfreq() const
83 Assert(started);
84 Assert(!at_end());
85 return current_position->termfreq;
88 TermList *
89 NetworkTermList::next()
91 if (started) {
92 Assert(!at_end());
93 ++current_position;
94 } else {
95 started = true;
97 return NULL;
100 TermList *
101 NetworkTermList::skip_to(const string & term)
103 while (current_position != items.end() && current_position->tname < term) {
104 ++current_position;
106 started = true;
107 return NULL;
110 bool
111 NetworkTermList::at_end() const
113 Assert(started);
114 return (current_position == items.end());
117 Xapian::termcount
118 NetworkTermList::positionlist_count() const
120 return this_db->positionlist_count(did, get_termname());
123 Xapian::PositionIterator
124 NetworkTermList::positionlist_begin() const
126 return Xapian::PositionIterator(this_db->open_position_list(did, get_termname()));