xapian-core  1.4.27
documentterm.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002 Ananova Ltd
6  * Copyright 2003,2007,2018 Olly Betts
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21  * USA
22  */
23 
24 #ifndef OM_HGUARD_DOCUMENTTERM_H
25 #define OM_HGUARD_DOCUMENTTERM_H
26 
27 #include "debuglog.h"
28 
29 #include <string>
30 #include <vector>
31 
32 #include <xapian/types.h>
33 
34 using std::string;
35 using std::vector;
36 
39  public:
45  : wdf(wdf_)
46  {
47  LOGCALL_CTOR(DB, "OmDocumentTerm", wdf_);
48  }
49 
54 
72  mutable unsigned split = 0;
73 
75  void merge() const;
76 
77  typedef vector<Xapian::termpos> term_positions;
78 
79  private:
93  mutable term_positions positions;
94 
95  public:
96  const term_positions* get_vector_termpos() const {
97  merge();
98  return &positions;
99  }
100 
102  return positions.size();
103  }
104 
105  void remove() {
106  positions.clear();
107  split = 1;
108  }
109 
120 
126  positions.push_back(termpos);
127  }
128 
138  void remove_position(Xapian::termpos tpos);
139 
150  Xapian::termpos termpos_last);
151 
157  if (rare(is_deleted())) {
158  split = 0;
159  wdf = delta;
160  return true;
161  }
162  wdf += delta;
163  return false;
164  }
165 
168  // Saturating arithmetic - don't let the wdf go below zero.
169  if (wdf >= delta) {
170  wdf -= delta;
171  } else {
172  wdf = 0;
173  }
174  }
175 
177  Xapian::termcount get_wdf() const { return wdf; }
178 
184  bool is_deleted() const { return positions.empty() && split > 0; }
185 
187  string get_description() const;
188 };
189 
190 #endif // OM_HGUARD_DOCUMENTTERM_H
OmDocumentTerm(Xapian::termcount wdf_)
Make a new term.
Definition: documentterm.h:44
typedefs for Xapian
Xapian::termcount wdf
Within document frequency of the term.
Definition: documentterm.h:53
void merge() const
Merge sorted ranges before and after split.
Definition: omdocument.cc:245
void decrease_wdf(Xapian::termcount delta)
Decrease within-document frequency.
Definition: documentterm.h:167
unsigned split
Split point in the position range.
Definition: documentterm.h:72
#define rare(COND)
Definition: config.h:575
bool is_deleted() const
Has this term been deleted from this document?
Definition: documentterm.h:184
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
string get_description() const
Return a string describing this object.
Definition: omdocument.cc:388
const term_positions * get_vector_termpos() const
Definition: documentterm.h:96
Xapian::termcount get_wdf() const
Get the wdf.
Definition: documentterm.h:177
term_positions positions
Positional information.
Definition: documentterm.h:93
vector< Xapian::termpos > term_positions
Definition: documentterm.h:77
A term in a document.
Definition: documentterm.h:38
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:489
Xapian::termcount positionlist_count() const
Definition: documentterm.h:101
bool increase_wdf(Xapian::termcount delta)
Increase within-document frequency.
Definition: documentterm.h:156
void remove_position(Xapian::termpos tpos)
Remove an entry from the position list.
Definition: omdocument.cc:324
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:83
void append_position(Xapian::termpos termpos)
Append a position.
Definition: documentterm.h:125
bool add_position(Xapian::termcount wdf_inc, Xapian::termpos termpos)
Add a position.
Definition: omdocument.cc:255
Debug logging macros.
Xapian::termpos remove_positions(Xapian::termpos termpos_first, Xapian::termpos termpos_last)
Remove a range of positions.
Definition: omdocument.cc:362