Add regression test for previous commit
[xapian.git] / xapian-core / queryparser / termgenerator.cc
blob63de1a0920a53589fc149de96ffc4d051d106ccf
1 /** @file
2 * @brief TermGenerator class implementation
3 */
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
21 #include <config.h>
23 #include <xapian/termgenerator.h>
24 #include <xapian/types.h>
25 #include <xapian/unicode.h>
27 #include "termgenerator_internal.h"
29 #include "str.h"
31 using namespace std;
32 using namespace Xapian;
34 TermGenerator::TermGenerator(const TermGenerator & o) : internal(o.internal) { }
36 TermGenerator &
37 TermGenerator::operator=(const TermGenerator & o) {
38 internal = o.internal;
39 return *this;
42 TermGenerator::TermGenerator(TermGenerator &&) = default;
44 TermGenerator &
45 TermGenerator::operator=(TermGenerator &&) = default;
47 TermGenerator::TermGenerator() : internal(new TermGenerator::Internal) { }
49 TermGenerator::~TermGenerator() { }
51 void
52 TermGenerator::set_stemmer(const Xapian::Stem & stemmer)
54 internal->stemmer = stemmer;
57 void
58 TermGenerator::set_stopper(const Xapian::Stopper * stopper)
60 internal->stopper = stopper;
63 void
64 TermGenerator::set_document(const Xapian::Document & doc)
66 internal->doc = doc;
67 internal->cur_pos = 0;
70 const Xapian::Document &
71 TermGenerator::get_document() const
73 return internal->doc;
76 void
77 TermGenerator::set_database(const Xapian::WritableDatabase &db)
79 internal->db = db;
82 TermGenerator::flags
83 TermGenerator::set_flags(flags toggle, flags mask)
85 TermGenerator::flags old_flags = internal->flags;
86 internal->flags = flags((old_flags & mask) ^ toggle);
87 return old_flags;
90 void
91 TermGenerator::set_stemming_strategy(stem_strategy strategy)
93 internal->strategy = strategy;
96 void
97 TermGenerator::set_stopper_strategy(stop_strategy strategy)
99 internal->stop_mode = strategy;
102 void
103 TermGenerator::set_max_word_length(unsigned max_word_length)
105 internal->max_word_length = max_word_length;
108 void
109 TermGenerator::index_text(const Xapian::Utf8Iterator & itor,
110 Xapian::termcount weight,
111 const string & prefix)
113 internal->index_text(itor, weight, prefix, true);
116 void
117 TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator & itor,
118 Xapian::termcount weight,
119 const string & prefix)
121 internal->index_text(itor, weight, prefix, false);
124 void
125 TermGenerator::increase_termpos(Xapian::termpos delta)
127 internal->cur_pos += delta;
130 Xapian::termpos
131 TermGenerator::get_termpos() const
133 return internal->cur_pos;
136 void
137 TermGenerator::set_termpos(Xapian::termpos termpos)
139 internal->cur_pos = termpos;
142 string
143 TermGenerator::get_description() const
145 string s("Xapian::TermGenerator(stem=");
146 s += internal->stemmer.get_description();
147 if (internal->stopper.get()) {
148 s += ", stopper set";
150 s += ", doc=";
151 s += internal->doc.get_description();
152 s += ", termpos=";
153 s += str(internal->cur_pos);
154 s += ")";
155 return s;