xapian-core  1.4.26
chert_modifiedpostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2006,2007,2008,2009,2010,2011,2014,2015 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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 #include "chert_modifiedpostlist.h"
23 
24 #include "chert_database.h"
25 #include "debuglog.h"
26 
28 {
29  delete poslist;
30 }
31 
32 void
34 {
35  while (!ChertPostList::at_end()) {
36  while (it != mods.end() && it->second.first == 'D' &&
37  it->first < ChertPostList::get_docid())
38  ++it;
39  if (it == mods.end()) return;
40  if (it->first != ChertPostList::get_docid()) return;
41  if (it->second.first != 'D') return;
42  ++it;
43  ChertPostList::next(w_min);
44  }
45  while (it != mods.end() && it->second.first == 'D') ++it;
46 }
47 
50 {
52  this_db->get_freqs(term, &tf, NULL);
53  return tf;
54 }
55 
58 {
59  if (it == mods.end()) return ChertPostList::get_docid();
60  if (ChertPostList::at_end()) return it->first;
61  Assert(it->second.first != 'D');
62  return min(it->first, ChertPostList::get_docid());
63 }
64 
67 {
68  LOGCALL(DB, Xapian::termcount, "ChertModifiedPostList::get_doclength", NO_ARGS);
69  if (it != mods.end() && (ChertPostList::at_end() || it->first <= ChertPostList::get_docid()))
70  RETURN(this_db->get_doclength(it->first));
72 }
73 
76 {
77  LOGCALL(DB, Xapian::termcount, "ChertModifiedPostList::get_unique_terms", NO_ARGS);
78  if (it != mods.end() && (ChertPostList::at_end() || it->first <= ChertPostList::get_docid()))
81 }
82 
85 {
86  if (ChertPostList::at_end()) return it->second.second;
88  if (it != mods.end() && it->first <= unmod_did) {
89  if (it->first < unmod_did) return it->second.second;
90  return it->second.second;
91  }
92  return ChertPostList::get_wdf();
93 }
94 
97 {
98  if (it != mods.end() && (ChertPostList::at_end() || it->first <= ChertPostList::get_docid())) {
99  if (poslist) {
100  delete poslist;
101  poslist = NULL;
102  }
104  return poslist;
105  }
107 }
108 
109 PositionList *
111 {
112  if (it != mods.end() && (ChertPostList::at_end() || it->first <= ChertPostList::get_docid())) {
113  return this_db->open_position_list(it->first, term);
114  }
116 }
117 
118 PostList *
120 {
121  if (have_started) {
122  if (ChertPostList::at_end()) {
123  ++it;
124  skip_deletes(w_min);
125  return NULL;
126  }
128  if (it != mods.end() && it->first <= unmod_did) {
129  if (it->first < unmod_did && it->second.first != 'D') {
130  ++it;
131  skip_deletes(w_min);
132  return NULL;
133  }
134  ++it;
135  }
136  }
137  ChertPostList::next(w_min);
138  skip_deletes(w_min);
139  return NULL;
140 }
141 
142 PostList *
144 {
145  if (!ChertPostList::at_end()) ChertPostList::skip_to(desired_did, w_min);
146  /* FIXME: should we use lower_bound() on the map? */
147  while (it != mods.end() && it->first < desired_did) ++it;
148  skip_deletes(w_min);
149  return NULL;
150 }
151 
152 bool
154  return it == mods.end() && ChertPostList::at_end();
155 }
156 
157 std::string
159 {
160  std::string desc = "ChertModifiedPostList(";
162  desc += ')';
163  return desc;
164 }
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
Abstract base class for postlists.
Definition: postlist.h:37
map< Xapian::docid, pair< char, Xapian::termcount > > mods
Modifications to apply to the ChertPostList.
Xapian::termcount get_doclength() const
Returns the length of current document.
Xapian::doccount get_termfreq() const
Return the exact term frequency.
Xapian::termcount get_doclength() const
Return the length of current document.
PositionList * read_position_list()
Read the position list for the term in the current document and return a pointer to it (owned by the ...
std::string get_description() const
Get a description of the document.
std::string term
The term name for this postlist (empty for an alldocs postlist).
Definition: leafpostlist.h:52
PositionList * open_position_list(Xapian::docid did, const string &term) const
Virtual methods of Database::Internal.
Xapian::docid get_docid() const
Returns the current docid.
PositionList * open_position_list() const
Get the list of positions of the term in the current document.
void skip_deletes(double w_min)
Skip over deleted documents after a next() or skip_to().
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
bool at_end() const
Return true if the current position is past the last entry in this list.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
bool have_started
Whether we&#39;ve started reading the list yet.
std::string get_description() const
Return a string description of this object.
Internal * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:194
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
PositionList * read_position_list()
Get the list of positions of the term in the current document.
PositionList * poslist
Pointer to PositionList returned from read_position_list to be deleted.
bool at_end() const
Return true if and only if we&#39;re off the end of the list.
PositionList * open_position_list() const
Read the position list for the term in the current document and return a pointer to it (not owned by ...
C++ class definition for chert database.
A ChertPostList plus pending modifications.
Xapian::docid get_docid() const
Return the current docid.
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
Xapian::termcount get_doclength(Xapian::docid did) const
Virtual methods of Database::Internal.
map< Xapian::docid, pair< char, Xapian::termcount > >::const_iterator it
Modifications to apply to the ChertPostList.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:31
PostList * skip_to(Xapian::docid desired_did, double w_min)
Skip forward to the specified docid.
PostList * skip_to(Xapian::docid desired_did, double w_min)
Skip to next document with docid >= docid.
Xapian::termcount get_wdf() const
Returns the Within Document Frequency of the term in the current document.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487
void get_freqs(const string &term, Xapian::doccount *termfreq_ptr, Xapian::termcount *collfreq_ptr) const
Virtual methods of Database::Internal.