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/stem.h>
00028 #include <xapian/termiterator.h>
00029
00030 #include <set>
00031 #include <string>
00032
00033 namespace Xapian {
00034
00036 class Stopper {
00037 public:
00039 virtual bool operator()(const std::string & term) const = 0;
00040
00042 virtual ~Stopper() { }
00043
00045 virtual std::string get_description() const;
00046 };
00047
00049 class SimpleStopper : public Stopper {
00050 private:
00051 std::set<std::string> stop_words;
00052
00053 public:
00055 SimpleStopper() { }
00056
00058 #ifndef __SUNPRO_CC
00059 template <class Iterator>
00060 SimpleStopper(Iterator begin, Iterator end) : stop_words(begin, end) { }
00061 #else
00062
00063 template <class Iterator>
00064 SimpleStopper(Iterator begin, Iterator end) {
00065 while (begin != end) stop_words.insert(*begin++);
00066 }
00067 #endif
00068
00070 void add(const std::string word) { stop_words.insert(word); }
00071
00073 virtual bool operator()(const std::string & term) const {
00074 return stop_words.find(term) != stop_words.end();
00075 }
00076
00078 virtual ~SimpleStopper() { }
00079
00081 virtual std::string get_description() const;
00082 };
00083
00085 class QueryParser {
00086 public:
00088 class Internal;
00090 Xapian::Internal::RefCntPtr<Internal> internal;
00091
00093 typedef enum {
00095 FLAG_BOOLEAN = 1,
00097 FLAG_PHRASE = 2,
00099 FLAG_LOVEHATE = 4,
00101 FLAG_BOOLEAN_ANY_CASE = 8,
00107 FLAG_WILDCARD = 16
00108 } feature_flag;
00109
00110 typedef enum { STEM_NONE, STEM_SOME, STEM_ALL } stem_strategy;
00111
00113 QueryParser(const QueryParser & o);
00114
00116 QueryParser & operator=(const QueryParser & o);
00117
00119 QueryParser();
00120
00122 ~QueryParser();
00123
00125 void set_stemmer(const Xapian::Stem & stemmer);
00126
00128 void set_stemming_strategy(stem_strategy strategy);
00129
00131 void set_stopper(const Stopper *stop = NULL);
00132
00150 XAPIAN_DEPRECATED(void set_stemming_options(const std::string &lang, bool stem_all = false,
00151 const Stopper *stop = NULL));
00152
00154 void set_default_op(Query::op default_op);
00155
00157 Query::op get_default_op() const;
00158
00160 void set_database(const Database &db);
00161
00169 Query parse_query(const std::string &query_string,
00170 unsigned flags = FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE);
00171
00184 void add_prefix(const std::string &field, const std::string &prefix);
00185
00201 void add_boolean_prefix(const std::string & field, const std::string &prefix);
00202
00204 TermIterator stoplist_begin() const;
00205 TermIterator stoplist_end() const {
00206 return TermIterator(NULL);
00207 }
00208
00210 TermIterator unstem_begin(const std::string &term) const;
00211 TermIterator unstem_end(const std::string &) const {
00212 return TermIterator(NULL);
00213 }
00214
00216 std::string get_description() const;
00217 };
00218
00219 }
00220
00221 #endif // XAPIAN_INCLUDED_QUERYPARSER_H