00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef XAPIAN_INCLUDED_QUERYPARSER_H
00023 #define XAPIAN_INCLUDED_QUERYPARSER_H
00024
00025 #include <xapian/base.h>
00026 #include <xapian/query.h>
00027 #include <xapian/termiterator.h>
00028 #include <xapian/visibility.h>
00029
00030 #include <set>
00031 #include <string>
00032
00033 namespace Xapian {
00034
00035 class Stem;
00036
00038 class XAPIAN_VISIBILITY_DEFAULT Stopper {
00039 public:
00041 virtual bool operator()(const std::string & term) const = 0;
00042
00044 virtual ~Stopper() { }
00045
00047 virtual std::string get_description() const;
00048 };
00049
00051 class XAPIAN_VISIBILITY_DEFAULT SimpleStopper : public Stopper {
00052 private:
00053 std::set<std::string> stop_words;
00054
00055 public:
00057 SimpleStopper() { }
00058
00060 #ifndef __SUNPRO_CC
00061 template <class Iterator>
00062 SimpleStopper(Iterator begin, Iterator end) : stop_words(begin, end) { }
00063 #else
00064
00065 template <class Iterator>
00066 SimpleStopper(Iterator begin, Iterator end) {
00067 while (begin != end) stop_words.insert(*begin++);
00068 }
00069 #endif
00070
00072 void add(const std::string & word) { stop_words.insert(word); }
00073
00075 virtual bool operator()(const std::string & term) const {
00076 return stop_words.find(term) != stop_words.end();
00077 }
00078
00080 virtual ~SimpleStopper() { }
00081
00083 virtual std::string get_description() const;
00084 };
00085
00087 struct XAPIAN_VISIBILITY_DEFAULT ValueRangeProcessor {
00089 virtual ~ValueRangeProcessor();
00090
00097 virtual Xapian::valueno operator()(std::string &begin, std::string &end) = 0;
00098 };
00099
00104 class XAPIAN_VISIBILITY_DEFAULT StringValueRangeProcessor : public ValueRangeProcessor {
00105 Xapian::valueno valno;
00106
00107 public:
00112 StringValueRangeProcessor(Xapian::valueno valno_)
00113 : valno(valno_) { }
00114
00116 Xapian::valueno operator()(std::string &, std::string &) {
00117 return valno;
00118 }
00119 };
00120
00125 class XAPIAN_VISIBILITY_DEFAULT DateValueRangeProcessor : public ValueRangeProcessor {
00126 Xapian::valueno valno;
00127 bool prefer_mdy;
00128 int epoch_year;
00129
00130 public:
00141 DateValueRangeProcessor(Xapian::valueno valno_, bool prefer_mdy_ = false,
00142 int epoch_year_ = 1970)
00143 : valno(valno_), prefer_mdy(prefer_mdy_), epoch_year(epoch_year_) { }
00144
00151 Xapian::valueno operator()(std::string &begin, std::string &end);
00152 };
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 #ifndef DOXYGEN
00165
00166 namespace v102 {
00167 #endif
00168
00176 class XAPIAN_VISIBILITY_DEFAULT NumberValueRangeProcessor : public ValueRangeProcessor {
00177 Xapian::valueno valno;
00178 bool prefix;
00179 std::string str;
00180
00181 public:
00186 NumberValueRangeProcessor(Xapian::valueno valno_)
00187 : valno(valno_), prefix(false) { }
00188
00221 NumberValueRangeProcessor(Xapian::valueno valno_, const std::string &str_,
00222 bool prefix_ = true)
00223 : valno(valno_), prefix(prefix_), str(str_) { }
00224
00234 Xapian::valueno operator()(std::string &begin, std::string &end);
00235 };
00236
00237 #ifndef DOXYGEN
00238 }
00239
00240 # ifndef XAPIAN_NO_V102_NUMBER_VRP
00241 using v102::NumberValueRangeProcessor;
00242 # endif
00243 #endif
00244
00246 class XAPIAN_VISIBILITY_DEFAULT QueryParser {
00247 public:
00249 class Internal;
00251 Xapian::Internal::RefCntPtr<Internal> internal;
00252
00254 typedef enum {
00256 FLAG_BOOLEAN = 1,
00258 FLAG_PHRASE = 2,
00260 FLAG_LOVEHATE = 4,
00262 FLAG_BOOLEAN_ANY_CASE = 8,
00268 FLAG_WILDCARD = 16,
00275 FLAG_PURE_NOT = 32,
00287 FLAG_PARTIAL = 64,
00288
00302 FLAG_SPELLING_CORRECTION = 128,
00303
00308 FLAG_SYNONYM = 256,
00309
00314 FLAG_AUTO_SYNONYMS = 512,
00315
00321 FLAG_AUTO_MULTIWORD_SYNONYMS = 1024 | FLAG_AUTO_SYNONYMS
00322 } feature_flag;
00323
00324 typedef enum { STEM_NONE, STEM_SOME, STEM_ALL } stem_strategy;
00325
00327 QueryParser(const QueryParser & o);
00328
00330 QueryParser & operator=(const QueryParser & o);
00331
00333 QueryParser();
00334
00336 ~QueryParser();
00337
00346 void set_stemmer(const Xapian::Stem & stemmer);
00347
00365 void set_stemming_strategy(stem_strategy strategy);
00366
00368 void set_stopper(const Stopper *stop = NULL);
00369
00371 void set_default_op(Query::op default_op);
00372
00374 Query::op get_default_op() const;
00375
00377 void set_database(const Database &db);
00378
00388 Query parse_query(const std::string &query_string,
00389 unsigned flags = FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE,
00390 const std::string &default_prefix = "");
00391
00427 void add_prefix(const std::string &field, const std::string &prefix);
00428
00474 void add_boolean_prefix(const std::string & field, const std::string &prefix);
00475
00477 TermIterator stoplist_begin() const;
00478 TermIterator stoplist_end() const {
00479 return TermIterator(NULL);
00480 }
00481
00483 TermIterator unstem_begin(const std::string &term) const;
00484 TermIterator unstem_end(const std::string &) const {
00485 return TermIterator(NULL);
00486 }
00487
00489 void add_valuerangeprocessor(Xapian::ValueRangeProcessor * vrproc);
00490
00498 std::string get_corrected_query_string() const;
00499
00501 std::string get_description() const;
00502 };
00503
00528 XAPIAN_VISIBILITY_DEFAULT
00529 std::string sortable_serialise(double value);
00530
00543 XAPIAN_VISIBILITY_DEFAULT
00544 double sortable_unserialise(const std::string & value);
00545
00546 }
00547
00548 #endif // XAPIAN_INCLUDED_QUERYPARSER_H