xapian-core  2.0.0
postingiterator.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2009,2010,2011,2013,2017 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 
23 #include "xapian/postingiterator.h"
24 
26 #include "debuglog.h"
27 #include "omassert.h"
28 
29 using namespace std;
30 
31 namespace Xapian {
32 
33 void
34 PostingIterator::decref()
35 {
36  Assert(internal);
37  if (--internal->_refs == 0)
38  delete internal;
39 }
40 
41 PostingIterator::PostingIterator(Internal *internal_) : internal(internal_)
42 {
43  LOGCALL_CTOR(API, "PostingIterator", internal_);
44  if (!internal) return;
45  try {
46  ++internal->_refs;
47  if (!internal->next()) {
48  decref();
49  internal = NULL;
50  }
51  } catch (...) {
52  // The destructor only runs if the constructor completes, so we have to
53  // take care of cleaning up for ourselves here.
54  decref();
55  throw;
56  }
57 }
58 
60  : internal(o.internal)
61 {
62  LOGCALL_CTOR(API, "PostingIterator", o);
63  if (internal)
64  ++internal->_refs;
65 }
66 
69 {
70  LOGCALL(API, PostingIterator &, "PostingIterator::operator=", o);
71  if (o.internal)
72  ++o.internal->_refs;
73  if (internal)
74  decref();
75  internal = o.internal;
76  RETURN(*this);
77 }
78 
81 {
82  LOGCALL(API, Xapian::docid, "PostingIterator::operator*", NO_ARGS);
83  Assert(internal);
85 }
86 
89 {
90  LOGCALL(API, PostingIterator &, "PostingIterator::operator++", NO_ARGS);
91  Assert(internal);
92  if (!internal->next()) {
93  decref();
94  internal = NULL;
95  }
96  RETURN(*this);
97 }
98 
101 {
102  LOGCALL(API, Xapian::termcount, "PostingIterator::get_wdf", NO_ARGS);
103  Assert(internal);
104  RETURN(internal->get_wdf());
105 }
106 
109 {
110  LOGCALL(API, Xapian::termcount, "PostingIterator::get_doclength", NO_ARGS);
111  Assert(internal);
113 }
114 
117 {
118  LOGCALL(API, Xapian::termcount, "PostingIterator::get_unique_terms", NO_ARGS);
119  Assert(internal);
121 }
122 
125 {
126  LOGCALL(API, Xapian::termcount, "PostingIterator::get_wdfdocmax", NO_ARGS);
127  Assert(internal);
129 }
130 
131 #if 0 // FIXME: TermIterator supports this, so PostingIterator really ought to.
133 PostingIterator::positionlist_count() const
134 {
135  LOGCALL(API, Xapian::termcount, "PostingIterator::positionlist_count", NO_ARGS);
136  Assert(internal);
137  RETURN(internal->positionlist_count());
138 }
139 #endif
140 
141 PositionIterator
143 {
144  LOGCALL(API, PositionIterator, "PostingIterator::positionlist_begin", NO_ARGS);
145  Assert(internal);
147 }
148 
149 void
151 {
152  LOGCALL_VOID(API, "PostingIterator::skip_to", did);
153  if (internal) {
154  if (!internal->skip_to(did)) {
155  decref();
156  internal = NULL;
157  }
158  }
159 }
160 
161 std::string
163 {
164  string desc = "PostingIterator(";
165  if (internal)
166  desc += internal->get_description();
167  desc += ')';
168  return desc;
169 }
170 
171 }
Class for iterating over term positions.
Xapian::termcount get_doclength() const
Xapian::termcount get_unique_terms() const
Xapian::termcount get_wdfdocmax() const
Class for iterating over a list of terms.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
void skip_to(Xapian::docid did)
Advance the iterator to document did.
Xapian::docid operator*() const
Return the document id at the current position.
PostingIterator & operator=(const PostingIterator &o)
Assignment.
std::string get_description() const
Return a string describing this object.
Xapian::termcount get_wdfdocmax() const
Return the max_wdf in the current document.
PostingIterator & operator++()
Advance the iterator to the next position.
Xapian::termcount get_doclength() const
Return the length of the document at the current position.
PositionIterator positionlist_begin() const
Return a PositionIterator for the current document.
PostingIterator() noexcept
Default constructor.
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
Debug logging macros.
#define RETURN(...)
Definition: debuglog.h:484
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:478
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:480
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:479
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Various assertion macros.
#define Assert(COND)
Definition: omassert.h:122
Class for iterating over a list of document ids.
Xapian::PostingIterator internals.