xapian-core  1.4.21
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 namespace std;
35 
38  public:
44  : wdf(wdf_)
45  {
46  LOGCALL_CTOR(DB, "OmDocumentTerm", wdf_);
47  }
48 
53 
71  mutable unsigned split = 0;
72 
74  void merge() const;
75 
76  typedef vector<Xapian::termpos> term_positions;
77 
78  private:
92  mutable term_positions positions;
93 
94  public:
95  const term_positions* get_vector_termpos() const {
96  merge();
97  return &positions;
98  }
99 
101  return positions.size();
102  }
103 
104  void remove() {
105  positions.clear();
106  split = 1;
107  }
108 
118  bool add_position(Xapian::termcount wdf_inc, Xapian::termpos termpos);
119 
125  positions.push_back(termpos);
126  }
127 
137  void remove_position(Xapian::termpos tpos);
138 
148  Xapian::termpos remove_positions(Xapian::termpos termpos_first,
149  Xapian::termpos termpos_last);
150 
156  if (rare(is_deleted())) {
157  split = 0;
158  wdf = delta;
159  return true;
160  }
161  wdf += delta;
162  return false;
163  }
164 
167  // Saturating arithmetic - don't let the wdf go below zero.
168  if (wdf >= delta) {
169  wdf -= delta;
170  } else {
171  wdf = 0;
172  }
173  }
174 
176  Xapian::termcount get_wdf() const { return wdf; }
177 
183  bool is_deleted() const { return positions.empty() && split > 0; }
184 
186  string get_description() const;
187 };
188 
189 #endif // OM_HGUARD_DOCUMENTTERM_H
OmDocumentTerm(Xapian::termcount wdf_)
Make a new term.
Definition: documentterm.h:43
typedefs for Xapian
Xapian::termcount wdf
Within document frequency of the term.
Definition: documentterm.h:52
void decrease_wdf(Xapian::termcount delta)
Decrease within-document frequency.
Definition: documentterm.h:166
STL namespace.
#define rare(COND)
Definition: config.h:573
bool is_deleted() const
Has this term been deleted from this document?
Definition: documentterm.h:183
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
const term_positions * get_vector_termpos() const
Definition: documentterm.h:95
Xapian::termcount get_wdf() const
Get the wdf.
Definition: documentterm.h:176
term_positions positions
Positional information.
Definition: documentterm.h:92
vector< Xapian::termpos > term_positions
Definition: documentterm.h:76
A term in a document.
Definition: documentterm.h:37
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:478
Xapian::termcount positionlist_count() const
Definition: documentterm.h:100
bool increase_wdf(Xapian::termcount delta)
Increase within-document frequency.
Definition: documentterm.h:155
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:124
Debug logging macros.