00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef XAPIAN_INCLUDED_QUERY_H
00026 #define XAPIAN_INCLUDED_QUERY_H
00027
00028 #include <string>
00029 #include <vector>
00030
00031 #include <xapian/base.h>
00032 #include <xapian/deprecated.h>
00033 #include <xapian/types.h>
00034 #include <xapian/termiterator.h>
00035 #include <xapian/visibility.h>
00036
00037
00038
00039
00040 class LocalSubMatch;
00041 class MultiMatch;
00042 class QueryOptimiser;
00043 struct SortPosName;
00044
00045 namespace Xapian {
00046
00051 class XAPIAN_VISIBILITY_DEFAULT Query {
00052 public:
00054 class Internal;
00056 Xapian::Internal::RefCntPtr<Internal> internal;
00057
00059 typedef enum {
00061 OP_AND,
00062
00064 OP_OR,
00065
00067 OP_AND_NOT,
00068
00070 OP_XOR,
00071
00073 OP_AND_MAYBE,
00074
00076 OP_FILTER,
00077
00087 OP_NEAR,
00088
00098 OP_PHRASE,
00099
00101 OP_VALUE_RANGE,
00102
00111 OP_SCALE_WEIGHT,
00112
00116 OP_ELITE_SET,
00117
00119 OP_VALUE_GE,
00120
00122 OP_VALUE_LE
00123 } op;
00124
00126 Query(const Query & copyme);
00127
00129 Query & operator=(const Query & copyme);
00130
00139 Query();
00140
00142 ~Query();
00143
00145 Query(const std::string & tname_, Xapian::termcount wqf_ = 1,
00146 Xapian::termpos pos_ = 0);
00147
00149 Query(Query::op op_, const Query & left, const Query & right);
00150
00152 Query(Query::op op_,
00153 const std::string & left, const std::string & right);
00154
00170 template <class Iterator>
00171 Query(Query::op op_, Iterator qbegin, Iterator qend,
00172 Xapian::termcount parameter = 0);
00173
00180 XAPIAN_DEPRECATED(Query(Query::op op_, Xapian::Query q));
00181
00185 Query(Query::op op_, Xapian::Query q, double parameter);
00186
00200 Query(Query::op op_, Xapian::valueno valno,
00201 const std::string &begin, const std::string &end);
00202
00214 Query(Query::op op_, Xapian::valueno valno, const std::string &value);
00215
00217 static Xapian::Query MatchAll;
00218
00220 static Xapian::Query MatchNothing;
00221
00226 Xapian::termcount get_length() const;
00227
00233 TermIterator get_terms_begin() const;
00234
00238 TermIterator get_terms_end() const {
00239 return TermIterator(NULL);
00240 }
00241
00245 bool empty() const;
00246
00248 std::string get_description() const;
00249
00250 private:
00251 void add_subquery(const Query & subq);
00252 void add_subquery(const Query * subq);
00253 void add_subquery(const std::string & tname);
00254 void start_construction(Query::op op_, Xapian::termcount parameter);
00255 void end_construction();
00256 void abort_construction();
00257 };
00258
00259 template <class Iterator>
00260 Query::Query(Query::op op_, Iterator qbegin, Iterator qend, termcount parameter)
00261 : internal(0)
00262 {
00263 try {
00264 start_construction(op_, parameter);
00265
00266
00267 while (qbegin != qend) {
00268 add_subquery(*qbegin);
00269 ++qbegin;
00270 }
00271
00272 end_construction();
00273 } catch (...) {
00274 abort_construction();
00275 throw;
00276 }
00277 }
00278
00280 class XAPIAN_VISIBILITY_DEFAULT Query::Internal : public Xapian::Internal::RefCntBase {
00281 friend class ::LocalSubMatch;
00282 friend class ::MultiMatch;
00283 friend class ::QueryOptimiser;
00284 friend struct ::SortPosName;
00285 friend class Query;
00286 public:
00287 static const int OP_LEAF = -1;
00288
00290 typedef std::vector<Internal *> subquery_list;
00291
00293 typedef int op_t;
00294
00295 private:
00297 Xapian::Query::Internal::op_t op;
00298
00300 subquery_list subqs;
00301
00309 Xapian::termcount parameter;
00310
00317 std::string tname;
00318
00320 std::string str_parameter;
00321
00323 Xapian::termpos term_pos;
00324
00326 Xapian::termcount wqf;
00327
00329 void initialise_from_copy(const Query::Internal & copyme);
00330
00331 void accumulate_terms(
00332 std::vector<std::pair<std::string, Xapian::termpos> > &terms) const;
00333
00338 Internal * simplify_query();
00339
00345 void validate_query() const;
00346
00352 bool simplify_matchnothing();
00353
00356 static std::string get_op_name(Xapian::Query::Internal::op_t op);
00357
00360 void collapse_subqs();
00361
00365 Xapian::Query::Internal * flatten_subqs();
00366
00369 std::string serialise(Xapian::termpos & curpos) const;
00370
00371 public:
00373 Internal(const Query::Internal & copyme);
00374
00376 void operator=(const Query::Internal & copyme);
00377
00379 explicit Internal(const std::string & tname_, Xapian::termcount wqf_ = 1,
00380 Xapian::termpos term_pos_ = 0);
00381
00383 Internal(op_t op_, Xapian::termcount parameter);
00384
00386 Internal(op_t op_, Xapian::valueno valno,
00387 const std::string &begin, const std::string &end);
00388
00391 Internal(op_t op_, Xapian::valueno valno, const std::string &value);
00392
00394 ~Internal();
00395
00396 static Xapian::Query::Internal * unserialise(const std::string &s);
00397
00399 void add_subquery(const Query::Internal * subq);
00400
00405 void add_subquery_nocopy(Query::Internal * subq);
00406
00407 void set_dbl_parameter(double dbl_parameter_);
00408
00409 double get_dbl_parameter() const;
00410
00413 Query::Internal * end_construction();
00414
00418 std::string serialise() const {
00419 Xapian::termpos curpos = 1;
00420 return serialise(curpos);
00421 }
00422
00424 std::string get_description() const;
00425
00433 Xapian::termcount get_parameter() const { return parameter; }
00434
00439 Xapian::termcount get_length() const;
00440
00446 TermIterator get_terms() const;
00447 };
00448
00449 }
00450
00451 #endif