00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef XAPIAN_INCLUDED_QUERY_H
00027 #define XAPIAN_INCLUDED_QUERY_H
00028
00029 #include <string>
00030 #include <vector>
00031
00032 #include <xapian/base.h>
00033 #include <xapian/types.h>
00034 #include <xapian/termiterator.h>
00035
00036
00037
00038
00039 class MultiMatch;
00040 class LocalSubMatch;
00041 class SortPosName;
00042
00043 namespace Xapian {
00044
00049 class Query {
00050 public:
00052 class Internal;
00054 Xapian::Internal::RefCntPtr<Internal> internal;
00055
00057 typedef enum {
00059 OP_AND,
00060
00062 OP_OR,
00063
00065 OP_AND_NOT,
00066
00068 OP_XOR,
00069
00071 OP_AND_MAYBE,
00072
00074 OP_FILTER,
00075
00084 OP_NEAR,
00085
00094 OP_PHRASE,
00095
00099 OP_ELITE_SET = 10
00100 } op;
00101
00103 Query(const Query & copyme);
00104
00106 Query & operator=(const Query & copyme);
00107
00116 Query();
00117
00119 ~Query();
00120
00122 Query(const std::string & tname_, Xapian::termcount wqf_ = 1,
00123 Xapian::termpos pos_ = 0);
00124
00126 Query(Query::op op_, const Query & left, const Query & right);
00127
00129 Query(Query::op op_,
00130 const std::string & left, const std::string & right);
00131
00147 template <class Iterator>
00148 Query(Query::op op_, Iterator qbegin, Iterator qend,
00149 Xapian::termcount parameter = 0);
00150
00152 Query(Query::op op_, Xapian::Query q);
00153
00158 Xapian::termcount get_length() const;
00159
00165 TermIterator get_terms_begin() const;
00166
00170 TermIterator get_terms_end() const {
00171 return TermIterator(NULL);
00172 }
00173
00177 bool empty() const;
00178
00180 bool is_empty() const { return empty(); }
00181
00185 std::string get_description() const;
00186
00187 private:
00188 void add_subquery(const Query & subq);
00189 void add_subquery(const Query * subq);
00190 void add_subquery(const std::string & tname);
00191 void start_construction(Query::op op_, Xapian::termcount parameter);
00192 void end_construction();
00193 void abort_construction();
00194 };
00195
00196 template <class Iterator>
00197 Query::Query(Query::op op_, Iterator qbegin, Iterator qend, termcount parameter)
00198 : internal(0)
00199 {
00200 try {
00201 start_construction(op_, parameter);
00202
00203
00204 while (qbegin != qend) {
00205 add_subquery(*qbegin);
00206 ++qbegin;
00207 }
00208
00209 end_construction();
00210 } catch (...) {
00211 abort_construction();
00212 throw;
00213 }
00214 }
00215
00217 class Query::Internal : public Xapian::Internal::RefCntBase {
00218 friend class ::MultiMatch;
00219 friend class ::LocalSubMatch;
00220 friend class ::SortPosName;
00221 public:
00222 static const int OP_LEAF = -1;
00223
00225 typedef std::vector<Internal *> subquery_list;
00226
00228 typedef int op_t;
00229
00230 private:
00232 op_t op;
00233
00235 subquery_list subqs;
00236
00242 Xapian::termcount parameter;
00243
00245 std::string tname;
00246
00248 Xapian::termpos term_pos;
00249
00251 Xapian::termcount wqf;
00252
00260 void swap(Query::Internal &other);
00261
00263 void initialise_from_copy(const Query::Internal & copyme);
00264
00265 void accumulate_terms(
00266 std::vector<std::pair<std::string, Xapian::termpos> > &terms) const;
00267
00272 Internal * simplify_query();
00273
00278 void prevalidate_query() const;
00279
00287 void validate_query() const;
00288
00291 static std::string get_op_name(Xapian::Query::Internal::op_t op);
00292
00295 void collapse_subqs();
00296
00300 void flatten_subqs();
00301
00302 public:
00304 Internal(const Query::Internal & copyme);
00305
00307 void operator=(const Query::Internal & copyme);
00308
00310 Internal(const std::string & tname_, Xapian::termcount wqf_ = 1,
00311 Xapian::termpos term_pos_ = 0);
00312
00314 Internal(op_t op_, Xapian::termcount parameter);
00315
00317 ~Internal();
00318
00319 static Xapian::Query::Internal * unserialise(const std::string &s);
00320
00323 void add_subquery(const Query::Internal & subq);
00324
00327 Query::Internal * end_construction();
00328
00332 std::string serialise() const;
00333
00337 std::string get_description() const;
00338
00343 Xapian::termcount get_length() const;
00344
00350 TermIterator get_terms() const;
00351 };
00352
00353 }
00354
00355 #endif