xapian-core  1.4.20
termgenerator.cc
Go to the documentation of this file.
1 
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 
34 TermGenerator::TermGenerator(const TermGenerator & o) : internal(o.internal) { }
35 
38  internal = o.internal;
39  return *this;
40 }
41 
43 
46 
48 
50 
51 void
53 {
54  internal->stemmer = stemmer;
55 }
56 
57 void
59 {
60  internal->stopper = stopper;
61 }
62 
63 void
65 {
66  internal->doc = doc;
67  internal->cur_pos = 0;
68 }
69 
70 const Xapian::Document &
72 {
73  return internal->doc;
74 }
75 
76 void
78 {
79  internal->db = db;
80 }
81 
84 {
85  TermGenerator::flags old_flags = internal->flags;
86  internal->flags = flags((old_flags & mask) ^ toggle);
87  return old_flags;
88 }
89 
90 void
92 {
93  internal->strategy = strategy;
94 }
95 
96 void
98 {
99  internal->stop_mode = strategy;
100 }
101 
102 void
103 TermGenerator::set_max_word_length(unsigned max_word_length)
104 {
105  internal->max_word_length = max_word_length;
106 }
107 
108 void
111  const string & prefix)
112 {
113  internal->index_text(itor, weight, prefix, true);
114 }
115 
116 void
119  const string & prefix)
120 {
121  internal->index_text(itor, weight, prefix, false);
122 }
123 
124 void
126 {
127  internal->cur_pos += delta;
128 }
129 
132 {
133  return internal->cur_pos;
134 }
135 
136 void
138 {
139  internal->cur_pos = termpos;
140 }
141 
142 string
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 }
Unicode and UTF-8 related classes and functions.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
void set_termpos(Xapian::termpos termpos)
Set the current term position.
typedefs for Xapian
Xapian::termpos get_termpos() const
Get the current term position.
Class representing a stemming algorithm.
Definition: stem.h:62
void set_document(const Xapian::Document &doc)
Set the current document.
double weight
The weight of a document or term.
Definition: types.h:122
Parses a piece of text and generate terms.
Definition: termgenerator.h:48
void set_stemming_strategy(stem_strategy strategy)
Set the stemming strategy.
const Xapian::Document & get_document() const
Get the current document.
STL namespace.
Convert types to std::string.
static Xapian::Stem stemmer
Definition: stemtest.cc:41
void index_text(const Xapian::Utf8Iterator &itor, Xapian::termcount wdf_inc=1, const std::string &prefix=std::string())
Index some text.
void set_database(const Xapian::WritableDatabase &db)
Set the database to index spelling data to.
TermGenerator class internals.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
stop_strategy
Stopper strategies, for use with set_stopper_strategy().
TermGenerator & operator=(const TermGenerator &o)
Assignment.
void set_stopper_strategy(stop_strategy strategy)
Set the stopper strategy.
stem_strategy
Stemming strategies, for use with set_stemming_strategy().
This class provides read/write access to a database.
Definition: database.h:785
parse free text and generate terms
~TermGenerator()
Destructor.
string str(int value)
Convert int to std::string.
Definition: str.cc:90
void set_stemmer(const Xapian::Stem &stemmer)
Set the Xapian::Stem object to be used for generating stemmed terms.
int flags
For backward compatibility with Xapian 1.2.
Definition: termgenerator.h:98
std::string get_description() const
Return a string describing this object.
void set_stopper(const Xapian::Stopper *stop=NULL)
Set the Xapian::Stopper object to be used for identifying stopwords.
void increase_termpos(Xapian::termpos delta=100)
Increase the term position used by index_text.
An iterator which returns Unicode character values from a UTF-8 encoded string.
Definition: unicode.h:38
TermGenerator()
Default constructor.
flags set_flags(flags toggle, flags mask=flags(0))
Set flags.
Xapian::Internal::intrusive_ptr< Internal > internal
Definition: termgenerator.h:51
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:83
void index_text_without_positions(const Xapian::Utf8Iterator &itor, Xapian::termcount wdf_inc=1, const std::string &prefix=std::string())
Index some text without positional information.
Abstract base class for stop-word decision functor.
Definition: queryparser.h:50
void set_max_word_length(unsigned max_word_length)
Set the maximum length word to index.
A handle representing a document in a Xapian database.
Definition: document.h:61