1 /** @file
2 * @brief TermGenerator class implementation
3 */
4 /* Copyright (C) 2007,2012 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
23 #include <xapian/termgenerator.h>
24 #include <xapian/types.h>
25 #include <xapian/unicode.h>
26
27 #include "termgenerator_internal.h"
28
29 #include "str.h"
30
31 using namespace std;
32 using namespace Xapian;
33
TermGenerator(const TermGenerator & o)34 TermGenerator::TermGenerator(const TermGenerator & o) : internal(o.internal) { }
35
36 TermGenerator &
operator =(const TermGenerator & o)37 TermGenerator::operator=(const TermGenerator & o) {
38 internal = o.internal;
39 return *this;
40 }
41
42 TermGenerator::TermGenerator(TermGenerator &&) = default;
43
44 TermGenerator &
45 TermGenerator::operator=(TermGenerator &&) = default;
46
TermGenerator()47 TermGenerator::TermGenerator() : internal(new TermGenerator::Internal) { }
48
~TermGenerator()49 TermGenerator::~TermGenerator() { }
50
51 void
set_stemmer(const Xapian::Stem & stemmer)52 TermGenerator::set_stemmer(const Xapian::Stem & stemmer)
53 {
54 internal->stemmer = stemmer;
55 }
56
57 void
set_stopper(const Xapian::Stopper * stopper)58 TermGenerator::set_stopper(const Xapian::Stopper * stopper)
59 {
60 internal->stopper = stopper;
61 }
62
63 void
set_document(const Xapian::Document & doc)64 TermGenerator::set_document(const Xapian::Document & doc)
65 {
66 internal->doc = doc;
67 internal->cur_pos = 0;
68 }
69
70 const Xapian::Document &
get_document() const71 TermGenerator::get_document() const
72 {
73 return internal->doc;
74 }
75
76 void
set_database(const Xapian::WritableDatabase & db)77 TermGenerator::set_database(const Xapian::WritableDatabase &db)
78 {
79 internal->db = db;
80 }
81
82 TermGenerator::flags
set_flags(flags toggle,flags mask)83 TermGenerator::set_flags(flags toggle, flags mask)
84 {
85 TermGenerator::flags old_flags = internal->flags;
86 internal->flags = flags((old_flags & mask) ^ toggle);
87 return old_flags;
88 }
89
90 void
set_stemming_strategy(stem_strategy strategy)91 TermGenerator::set_stemming_strategy(stem_strategy strategy)
92 {
93 internal->strategy = strategy;
94 }
95
96 void
set_stopper_strategy(stop_strategy strategy)97 TermGenerator::set_stopper_strategy(stop_strategy strategy)
98 {
99 internal->stop_mode = strategy;
100 }
101
102 void
set_max_word_length(unsigned max_word_length)103 TermGenerator::set_max_word_length(unsigned max_word_length)
104 {
105 internal->max_word_length = max_word_length;
106 }
107
108 void
index_text(const Xapian::Utf8Iterator & itor,Xapian::termcount weight,const string & prefix)109 TermGenerator::index_text(const Xapian::Utf8Iterator & itor,
110 Xapian::termcount weight,
111 const string & prefix)
112 {
113 internal->index_text(itor, weight, prefix, true);
114 }
115
116 void
index_text_without_positions(const Xapian::Utf8Iterator & itor,Xapian::termcount weight,const string & prefix)117 TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator & itor,
118 Xapian::termcount weight,
119 const string & prefix)
120 {
121 internal->index_text(itor, weight, prefix, false);
122 }
123
124 void
increase_termpos(Xapian::termpos delta)125 TermGenerator::increase_termpos(Xapian::termpos delta)
126 {
127 internal->cur_pos += delta;
128 }
129
130 Xapian::termpos
get_termpos() const131 TermGenerator::get_termpos() const
132 {
133 return internal->cur_pos;
134 }
135
136 void
set_termpos(Xapian::termpos termpos)137 TermGenerator::set_termpos(Xapian::termpos termpos)
138 {
139 internal->cur_pos = termpos;
140 }
141
142 string
get_description() const143 TermGenerator::get_description() const
144 {
145 string s("Xapian::TermGenerator(stem=");
146 s += internal->stemmer.get_description();
147 if (internal->stopper.get()) {
148 s += ", stopper set";
149 }
150 s += ", doc=";
151 s += internal->doc.get_description();
152 s += ", termpos=";
153 s += str(internal->cur_pos);
154 s += ")";
155 return s;
156 }
157