xapian-core  2.0.0
termgenerator.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2009,2011,2012,2013,2014,2018,2023,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 #ifndef XAPIAN_INCLUDED_TERMGENERATOR_H
22 #define XAPIAN_INCLUDED_TERMGENERATOR_H
23 
24 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
25 # error Never use <xapian/termgenerator.h> directly; include <xapian.h> instead.
26 #endif
27 
28 #include <xapian/intrusive_ptr.h>
29 #include <xapian/types.h>
30 #include <xapian/unicode.h>
31 #include <xapian/visibility.h>
32 
33 #include <string>
34 #include <string_view>
35 
36 namespace Xapian {
37 
38 class Document;
39 class Stem;
40 class Stopper;
41 class WritableDatabase;
42 
50  public:
52  class Internal;
55 
58 
61 
64 
67 
69  TermGenerator();
70 
72  ~TermGenerator();
73 
75  void set_stemmer(const Xapian::Stem & stemmer);
76 
85  void set_stopper(const Xapian::Stopper *stop = NULL);
86 
88  void set_document(const Xapian::Document & doc);
89 
91  const Xapian::Document & get_document() const;
92 
94  void set_database(const Xapian::WritableDatabase &db);
95 
97  typedef int flags;
98 
100  enum {
102  FLAG_SPELLING = 128, // Value matches QueryParser flag.
103 
126  FLAG_NGRAMS = 2048, // Value matches QueryParser flag.
127 
135  FLAG_CJK_NGRAM = FLAG_NGRAMS, // Value matches QueryParser flag.
136 
149  FLAG_WORD_BREAKS = 4096 // Value matches QueryParser flag
150  };
151 
153  typedef enum {
154  STEM_NONE, STEM_SOME, STEM_ALL, STEM_ALL_Z, STEM_SOME_FULL_POS
155  } stem_strategy;
156 
158  typedef enum { STOP_NONE, STOP_ALL, STOP_STEMMED } stop_strategy;
159 
172  flags set_flags(flags toggle, flags mask = flags(0));
173 
193  void set_stemming_strategy(stem_strategy strategy);
194 
214  void set_stopper_strategy(stop_strategy strategy);
215 
231  void set_max_word_length(unsigned max_word_length);
232 
239  void index_text(const Xapian::Utf8Iterator & itor,
240  Xapian::termcount wdf_inc = 1,
241  std::string_view prefix = {});
242 
249  void index_text(std::string_view text,
250  Xapian::termcount wdf_inc = 1,
251  std::string_view prefix = {}) {
252  index_text(Utf8Iterator(text), wdf_inc, prefix);
253  }
254 
265  void index_text_without_positions(const Xapian::Utf8Iterator & itor,
266  Xapian::termcount wdf_inc = 1,
267  std::string_view prefix = {});
268 
279  void index_text_without_positions(std::string_view text,
280  Xapian::termcount wdf_inc = 1,
281  std::string_view prefix = {}) {
282  index_text_without_positions(Utf8Iterator(text), wdf_inc, prefix);
283  }
284 
293  void increase_termpos(Xapian::termpos delta = 100);
294 
296  Xapian::termpos get_termpos() const;
297 
302  void set_termpos(Xapian::termpos termpos);
303 
313  void set_termpos_limit(Xapian::termpos termpos_limit);
314 
316  std::string get_description() const;
317 };
318 
319 }
320 
321 #endif // XAPIAN_INCLUDED_TERMGENERATOR_H
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
Parses a piece of text and generate terms.
Definition: termgenerator.h:49
TermGenerator & operator=(const TermGenerator &o)
Assignment.
TermGenerator(TermGenerator &&o)
Move constructor.
void index_text_without_positions(std::string_view text, Xapian::termcount wdf_inc=1, std::string_view prefix={})
Index some text without positional information.
void index_text(std::string_view text, Xapian::termcount wdf_inc=1, std::string_view prefix={})
Index some text.
int flags
For backward compatibility with Xapian 1.2.
Definition: termgenerator.h:97
TermGenerator & operator=(TermGenerator &&o)
Move assignment operator.
TermGenerator(const TermGenerator &o)
Copy constructor.
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
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
typedefs for Xapian
Unicode and UTF-8 related classes and functions.
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28