1 /** @file termgenerator.cc
2 * @brief TermGenerator class implementation
4 /* Copyright (C) 2007,2012 Olly Betts
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.
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.
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
23 #include <xapian/termgenerator.h>
24 #include <xapian/types.h>
25 #include <xapian/unicode.h>
27 #include "termgenerator_internal.h"
32 using namespace Xapian
;
34 TermGenerator::TermGenerator(const TermGenerator
&) = default;
37 TermGenerator::operator=(const TermGenerator
&) = default;
39 TermGenerator::TermGenerator(TermGenerator
&&) = default;
42 TermGenerator::operator=(TermGenerator
&&) = default;
44 TermGenerator::TermGenerator() : internal(new TermGenerator::Internal
) { }
46 TermGenerator::~TermGenerator() { }
49 TermGenerator::set_stemmer(const Xapian::Stem
& stemmer
)
51 internal
->stemmer
= stemmer
;
55 TermGenerator::set_stopper(const Xapian::Stopper
* stopper
)
57 internal
->stopper
= stopper
;
61 TermGenerator::set_document(const Xapian::Document
& doc
)
64 internal
->cur_pos
= 0;
67 const Xapian::Document
&
68 TermGenerator::get_document() const
74 TermGenerator::set_database(const Xapian::WritableDatabase
&db
)
80 TermGenerator::set_flags(flags toggle
, flags mask
)
82 TermGenerator::flags old_flags
= internal
->flags
;
83 internal
->flags
= flags((old_flags
& mask
) ^ toggle
);
88 TermGenerator::set_stemming_strategy(stem_strategy strategy
)
90 internal
->strategy
= strategy
;
94 TermGenerator::set_stopper_strategy(stop_strategy strategy
)
96 internal
->stop_mode
= strategy
;
100 TermGenerator::set_max_word_length(unsigned max_word_length
)
102 internal
->max_word_length
= max_word_length
;
106 TermGenerator::index_text(const Xapian::Utf8Iterator
& itor
,
107 Xapian::termcount weight
,
108 const string
& prefix
)
110 internal
->index_text(itor
, weight
, prefix
, true);
114 TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator
& itor
,
115 Xapian::termcount weight
,
116 const string
& prefix
)
118 internal
->index_text(itor
, weight
, prefix
, false);
122 TermGenerator::increase_termpos(Xapian::termpos delta
)
124 internal
->cur_pos
+= delta
;
128 TermGenerator::get_termpos() const
130 return internal
->cur_pos
;
134 TermGenerator::set_termpos(Xapian::termpos termpos
)
136 internal
->cur_pos
= termpos
;
140 TermGenerator::get_description() const
142 string
s("Xapian::TermGenerator(stem=");
143 s
+= internal
->stemmer
.get_description();
144 if (internal
->stopper
.get()) {
145 s
+= ", stopper set";
148 s
+= internal
->doc
.get_description();
150 s
+= str(internal
->cur_pos
);