xapian-core  2.0.0
termgenerator.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2012,2024 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, see
18  * <https://www.gnu.org/licenses/>.
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 #include <string_view>
32 
33 using namespace std;
34 using namespace Xapian;
35 
36 TermGenerator::TermGenerator(const TermGenerator &) = default;
37 
39 TermGenerator::operator=(const TermGenerator &) = default;
40 
41 TermGenerator::TermGenerator(TermGenerator &&) = default;
42 
44 TermGenerator::operator=(TermGenerator &&) = default;
45 
46 TermGenerator::TermGenerator() : internal(new TermGenerator::Internal) { }
47 
49 
50 void
52 {
53  internal->stemmer = stemmer;
54 }
55 
56 void
58 {
59  internal->stopper = stopper;
60 }
61 
62 void
64 {
65  internal->doc = doc;
66  internal->cur_pos = 0;
67 }
68 
69 const Xapian::Document &
71 {
72  return internal->doc;
73 }
74 
75 void
77 {
78  internal->db = db;
79 }
80 
83 {
84  TermGenerator::flags old_flags = internal->flags;
85  internal->flags = flags((old_flags & mask) ^ toggle);
86  return old_flags;
87 }
88 
89 void
91 {
92  internal->strategy = strategy;
93 }
94 
95 void
97 {
98  internal->stop_mode = strategy;
99 }
100 
101 void
102 TermGenerator::set_max_word_length(unsigned max_word_length)
103 {
104  internal->max_word_length = max_word_length;
105 }
106 
107 void
109  Xapian::termcount weight,
110  string_view prefix)
111 {
112  internal->index_text(itor, weight, prefix, true);
113 }
114 
115 void
117  Xapian::termcount weight,
118  string_view prefix)
119 {
120  internal->index_text(itor, weight, prefix, false);
121 }
122 
123 void
125 {
126  internal->cur_pos += delta;
127 }
128 
131 {
132  return internal->cur_pos;
133 }
134 
135 void
137 {
138  internal->cur_pos = termpos;
139 }
140 
141 void
143 {
144  internal->pos_limit = termpos_limit;
145 }
146 
147 string
149 {
150  string s("Xapian::TermGenerator(stem=");
151  s += internal->stemmer.get_description();
152  if (internal->stopper) {
153  s += ", stopper set";
154  }
155  s += ", doc=";
156  s += internal->doc.get_description();
157  s += ", termpos=";
158  s += str(internal->cur_pos);
159  s += ")";
160  return s;
161 }
Class representing a document.
Definition: document.h:64
Class representing a stemming algorithm.
Definition: stem.h:74
Abstract base class for stop-word decision functor.
Definition: queryparser.h:50
Xapian::Internal::opt_intrusive_ptr< const Stopper > stopper
Parses a piece of text and generate terms.
Definition: termgenerator.h:49
~TermGenerator()
Destructor.
void set_max_word_length(unsigned max_word_length)
Set the maximum length word to index.
void set_stopper_strategy(stop_strategy strategy)
Set the stopper strategy.
const Xapian::Document & get_document() const
Get the current document.
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
Definition: termgenerator.h:52
void index_text(const Xapian::Utf8Iterator &itor, Xapian::termcount wdf_inc=1, std::string_view prefix={})
Index some text.
void set_termpos(Xapian::termpos termpos)
Set the current term position.
stem_strategy
Stemming strategies, for use with set_stemming_strategy().
void set_document(const Xapian::Document &doc)
Set the current document.
flags set_flags(flags toggle, flags mask=flags(0))
Set flags.
void increase_termpos(Xapian::termpos delta=100)
Increase the term position used by index_text.
std::string get_description() const
Return a string describing this object.
int flags
For backward compatibility with Xapian 1.2.
Definition: termgenerator.h:97
void set_termpos_limit(Xapian::termpos termpos_limit)
Set the term position limit.
stop_strategy
Stopper strategies, for use with set_stopper_strategy().
void set_stopper(const Xapian::Stopper *stop=NULL)
Set the Xapian::Stopper object to be used for identifying stopwords.
void set_database(const Xapian::WritableDatabase &db)
Set the database to index spelling data to.
void set_stemming_strategy(stem_strategy strategy)
Set the stemming strategy.
void index_text_without_positions(const Xapian::Utf8Iterator &itor, Xapian::termcount wdf_inc=1, std::string_view prefix={})
Index some text without positional information.
Xapian::termpos get_termpos() const
Get the current term position.
void set_stemmer(const Xapian::Stem &stemmer)
Set the Xapian::Stem object to be used for generating stemmed terms.
An iterator which returns Unicode character values from a UTF-8 encoded string.
Definition: unicode.h:39
This class provides read/write access to a database.
Definition: database.h:964
string str(int value)
Convert int to std::string.
Definition: str.cc:91
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:75
static Xapian::Stem stemmer
Definition: stemtest.cc:42
Convert types to std::string.
parse free text and generate terms
TermGenerator class internals.
typedefs for Xapian
Unicode and UTF-8 related classes and functions.