xapian-core  1.4.26
chert_alldocsmodifiedpostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008 Lemur Consulting Ltd
5  * Copyright (C) 2006,2007,2008,2009,2010,2011,2015 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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 USA
20  */
21 
22 #include <config.h>
24 
25 #include "chert_database.h"
26 #include "debuglog.h"
27 #include "str.h"
28 
29 using namespace std;
31 
33  Xapian::doccount doccount_,
34  const map<Xapian::docid, Xapian::termcount> & doclens_)
35  : ChertAllDocsPostList(db_, doccount_),
36  doclens(doclens_),
37  doclens_it(doclens.begin())
38 {
39  LOGCALL_CTOR(DB, "ChertAllDocsModifiedPostList", db_.get() | doccount_ | doclens_);
40 }
41 
42 void
44 {
45  LOGCALL_VOID(DB, "ChertAllDocsModifiedPostList::skip_deletes", w_min);
46  while (!ChertAllDocsPostList::at_end()) {
47  if (doclens_it == doclens.end()) return;
48  if (doclens_it->first != ChertAllDocsPostList::get_docid()) return;
49  if (doclens_it->second != static_cast<Xapian::termcount>(-1)) return;
50  ++doclens_it;
52  }
53  while (doclens_it != doclens.end() && doclens_it->second == static_cast<Xapian::termcount>(-1)) {
54  ++doclens_it;
55  }
56 }
57 
60 {
61  LOGCALL(DB, Xapian::docid, "ChertAllDocsModifiedPostList::get_docid", NO_ARGS);
65 }
66 
69 {
70  LOGCALL(DB, Xapian::termcount, "ChertAllDocsModifiedPostList::get_doclength", NO_ARGS);
71  // Override with value from doclens_it (which cannot be -1, because that
72  // would have been skipped past).
73  if (doclens_it != doclens.end() &&
76  RETURN(doclens_it->second);
77 
79 }
80 
83 {
84  LOGCALL(DB, Xapian::termcount, "ChertAllDocsModifiedPostList::get_unique_terms", NO_ARGS);
85  Assert(this_db.get());
87 }
88 
89 PostList *
91 {
92  LOGCALL(DB, PostList *, "ChertAllDocsModifiedPostList::next", w_min);
93  if (have_started) {
95  ++doclens_it;
96  skip_deletes(w_min);
97  RETURN(NULL);
98  }
100  if (doclens_it != doclens.end() && doclens_it->first <= unmod_did) {
101  if (doclens_it->first < unmod_did &&
102  doclens_it->second != static_cast<Xapian::termcount>(-1)) {
103  ++doclens_it;
104  skip_deletes(w_min);
105  RETURN(NULL);
106  }
107  ++doclens_it;
108  }
109  }
111  skip_deletes(w_min);
112  RETURN(NULL);
113 }
114 
115 PostList *
117  double w_min)
118 {
119  LOGCALL(DB, PostList *, "ChertAllDocsModifiedPostList::skip_to", desired_did | w_min);
121  ChertAllDocsPostList::skip_to(desired_did, w_min);
122  /* FIXME: should we use lower_bound() on the map? */
123  while (doclens_it != doclens.end() && doclens_it->first < desired_did) {
124  ++doclens_it;
125  }
126  skip_deletes(w_min);
127  RETURN(NULL);
128 }
129 
130 bool
132 {
133  LOGCALL(DB, bool, "ChertAllDocsModifiedPostList::at_end", NO_ARGS);
135 }
136 
137 string
139 {
140  string desc = "ChertAllDocsModifiedPostList(did=";
141  desc += str(get_docid());
142  desc += ')';
143  return desc;
144 }
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
Abstract base class for postlists.
Definition: postlist.h:37
void skip_deletes(double w_min)
Skip over deleted documents after a next() or skip_to().
map< Xapian::docid, Xapian::termcount >::const_iterator doclens_it
Current position in the doclens list.
map< Xapian::docid, Xapian::termcount > doclens
Modifications to apply to the ChertAllDocsPostList.
Xapian::docid get_docid() const
Return the current docid.
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:488
STL namespace.
Convert types to std::string.
Xapian::docid get_docid() const
Returns the current docid.
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
Xapian::termcount get_unique_terms(Xapian::docid did) const
Virtual methods of Database::Internal.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
ChertAllDocsModifiedPostList(const ChertAllDocsModifiedPostList &)
Don&#39;t allow copying.
PostList * skip_to(Xapian::docid desired_did, double w_min)
Skip forward to the specified docid.
bool have_started
Whether we&#39;ve started reading the list yet.
A ChertAllDocsPostList plus pending modifications.
Internal * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:194
string str(int value)
Convert int to std::string.
Definition: str.cc:90
bool at_end() const
Return true if the current position is past the last entry in this list.
bool at_end() const
Return true if and only if we&#39;re off the end of the list.
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:489
C++ class definition for chert database.
Xapian::termcount get_doclength() const
Return the length of current document.
Xapian::Internal::intrusive_ptr< const ChertDatabase > this_db
The database we are searching.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
std::string get_description() const
Return a string description of this object.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:81
PostList * skip_to(Xapian::docid desired_did, double w_min)
Skip to next document with docid >= docid.
Xapian::termcount get_doclength() const
Return the length of current document.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487