Website now in git not CVS
[xapian.git] / xapian-core / api / documentterm.h
blob616329b82b12a2c632e11f2ffb1834eaf79ec59b
1 /** @file documentterm.h
2 * @brief internal class representing a term in a modified document
3 */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002 Ananova Ltd
6 * Copyright 2003,2007 Olly Betts
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.
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.
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
24 #ifndef OM_HGUARD_DOCUMENTTERM_H
25 #define OM_HGUARD_DOCUMENTTERM_H
27 #include "debuglog.h"
29 #include <string>
30 #include <vector>
32 #include <xapian/types.h>
34 using namespace std;
36 /// A term in a document.
37 class OmDocumentTerm {
38 public:
39 /** Make a new term.
41 * @param wdf_ Initial wdf.
43 explicit OmDocumentTerm(Xapian::termcount wdf_)
44 : wdf(wdf_)
46 LOGCALL_CTOR(DB, "OmDocumentTerm", wdf_);
49 /** Within document frequency of the term.
50 * This is the number of occurrences of the term in the document.
52 Xapian::termcount wdf;
54 typedef vector<Xapian::termpos> term_positions;
56 /** Positional information.
58 * This is a list of positions at which the term occurs in the
59 * document. The list is in strictly increasing order of term
60 * position.
62 * The positions start at 1.
64 * Note that, even if positional information is present, the WDF might
65 * not be equal to the length of the position list, since a term might
66 * occur multiple times at a single position, but will only have one
67 * entry in the position list for each position.
69 term_positions positions;
71 /** Add a position to the position list.
73 * This adds an entry to the list of positions, unless
74 * there is already one for the specified position.
76 * This does not change the value of the wdf.
78 * @param tpos The position within the document at which the term
79 * occurs.
81 void add_position(Xapian::termpos tpos);
83 /** Remove an entry from the position list.
85 * This removes an entry from the list of positions.
87 * This does not change the value of the wdf.
89 * @exception Xapian::InvalidArgumentError is thrown if the position does
90 * not occur in the position list.
92 void remove_position(Xapian::termpos tpos);
94 /// Increase the wdf
95 void inc_wdf(Xapian::termcount inc) { wdf += inc; }
97 /// Decrease the wdf
98 void dec_wdf(Xapian::termcount dec) {
99 if (wdf <= dec) {
100 wdf = 0;
101 } else {
102 wdf -= dec;
106 /// Get the wdf
107 Xapian::termcount get_wdf() const { return wdf; }
109 /// Return a string describing this object.
110 string get_description() const;
113 #endif // OM_HGUARD_DOCUMENTTERM_H