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
00035
00036
00037
00038 class MultiMatch;
00039 class LocalSubMatch;
00040 class SortPosName;
00041
00042 namespace Xapian {
00043
00044 class TermIterator;
00045
00050 class Query {
00051 public:
00053 class Internal;
00055 Xapian::Internal::RefCntPtr<Internal> internal;
00056
00058 typedef enum {
00060 OP_AND,
00061
00063 OP_OR,
00064
00066 OP_AND_NOT,
00067
00069 OP_XOR,
00070
00072 OP_AND_MAYBE,
00073
00075 OP_FILTER,
00076
00085 OP_NEAR,
00086
00095 OP_PHRASE,
00096
00103 OP_WEIGHT_CUTOFF,
00104
00108 OP_ELITE_SET
00109 } op;
00110
00112 Query(const Query & copyme);
00113
00115 Query & operator=(const Query & copyme);
00116
00125 Query();
00126
00128 ~Query();
00129
00131 Query(const std::string & tname_, Xapian::termcount wqf_ = 1,
00132 Xapian::termpos pos_ = 0);
00133
00135 Query(Query::op op_, const Query & left, const Query & right);
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00147 Query(Query::op op_,
00148 const std::string & left, const std::string & right);
00149
00163 template <class Iterator>
00164 Query(Query::op op_, Iterator qbegin, Iterator qend);
00165
00171 template <class SubQ> Query(Query::op op_, SubQ q);
00172
00175 void set_window(Xapian::termpos window);
00176
00179 void set_cutoff(Xapian::weight cutoff);
00180
00182 void set_elite_set_size(Xapian::termcount size);
00183
00188 Xapian::termcount get_length() const;
00189
00195 Xapian::termcount set_length(Xapian::termcount qlen);
00196
00202 TermIterator get_terms_begin() const;
00203
00207 TermIterator get_terms_end() const;
00208
00212 bool is_empty() const;
00213
00217 std::string get_description() const;
00218
00219 private:
00220 void add_subquery(const Query & subq);
00221 void add_subquery(const Query * subq);
00222 void add_subquery(const std::string & tname);
00223 void start_construction(Query::op op_);
00224 void end_construction();
00225 void abort_construction();
00226 };
00227
00228 template <class Iterator>
00229 Query::Query(Query::op op_, Iterator qbegin, Iterator qend) : internal(0)
00230 {
00231 try {
00232 start_construction(op_);
00233
00234
00235 while (qbegin != qend) {
00236 add_subquery(*qbegin);
00237 ++qbegin;
00238 }
00239
00240 end_construction();
00241 } catch (...) {
00242 abort_construction();
00243 throw;
00244 }
00245 }
00246
00247 template <class SubQ>
00248 Query::Query(Query::op op_, SubQ q) : internal(0)
00249 {
00250 try {
00251 start_construction(op_);
00252 add_subquery(q);
00253 end_construction();
00254 } catch (...) {
00255 abort_construction();
00256 throw;
00257 }
00258 }
00259
00261 class Query::Internal : public Xapian::Internal::RefCntBase {
00262 friend class ::MultiMatch;
00263 friend class ::LocalSubMatch;
00264 friend class ::SortPosName;
00265 public:
00266 static const int OP_LEAF = -1;
00267
00269 typedef std::vector<Internal *> subquery_list;
00270
00272 typedef int op_t;
00273
00274 private:
00276 op_t op;
00277
00279 subquery_list subqs;
00280
00282 Xapian::termcount qlen;
00283
00287 Xapian::termpos window;
00288
00291 double cutoff;
00292
00295 Xapian::termcount elite_set_size;
00296
00298 std::string tname;
00299
00301 Xapian::termpos term_pos;
00302
00304 Xapian::termcount wqf;
00305
00313 void swap(Query::Internal &other);
00314
00316 void initialise_from_copy(const Query::Internal & copyme);
00317
00318 void accumulate_terms(
00319 std::vector<std::pair<std::string, Xapian::termpos> > &terms) const;
00320
00325 Internal * simplify_query();
00326
00331 void prevalidate_query() const;
00332
00340 void validate_query() const;
00341
00344 static std::string get_op_name(Xapian::Query::Internal::op_t op);
00345
00348 void collapse_subqs();
00349
00353 void flatten_subqs();
00354
00355 public:
00357 Internal(const Query::Internal & copyme);
00358
00360 void operator=(const Query::Internal & copyme);
00361
00363 Internal(const std::string & tname_, Xapian::termcount wqf_ = 1,
00364 Xapian::termpos term_pos_ = 0);
00365
00367 Internal(op_t op_);
00368
00370 ~Internal();
00371
00372 static Xapian::Query::Internal * unserialise(const std::string &s);
00373
00376 void add_subquery(const Query::Internal & subq);
00377
00380 Query::Internal * end_construction();
00381
00385 std::string serialise() const;
00386
00390 std::string get_description() const;
00391
00393 void set_window(Xapian::termpos window);
00394
00396 void set_cutoff(double cutoff);
00397
00399 void set_elite_set_size(Xapian::termcount size);
00400
00405 Xapian::termcount get_length() const { return qlen; }
00406
00412 Xapian::termcount set_length(Xapian::termcount qlen_);
00413
00419 TermIterator get_terms() const;
00420 };
00421
00422 }
00423
00424 #endif