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
00086 OP_NEAR,
00087
00096 OP_PHRASE,
00097
00099 OP_VALUE_RANGE,
00100
00109 OP_SCALE_WEIGHT,
00110
00114 OP_ELITE_SET
00115 } op;
00116
00118 Query(const Query & copyme);
00119
00121 Query & operator=(const Query & copyme);
00122
00131 Query();
00132
00134 ~Query();
00135
00137 Query(const std::string & tname_, Xapian::termcount wqf_ = 1,
00138 Xapian::termpos pos_ = 0);
00139
00141 Query(Query::op op_, const Query & left, const Query & right);
00142
00144 Query(Query::op op_,
00145 const std::string & left, const std::string & right);
00146
00162 template <class Iterator>
00163 Query(Query::op op_, Iterator qbegin, Iterator qend,
00164 Xapian::termcount parameter = 0);
00165
00172 XAPIAN_DEPRECATED(Query(Query::op op_, Xapian::Query q));
00173
00177 Query(Query::op op_, Xapian::Query q, double parameter);
00178
00192 Query(Query::op op_, Xapian::valueno valno,
00193 const std::string &begin, const std::string &end);
00194
00196 static Xapian::Query MatchAll;
00197
00199 static Xapian::Query MatchNothing;
00200
00205 Xapian::termcount get_length() const;
00206
00212 TermIterator get_terms_begin() const;
00213
00217 TermIterator get_terms_end() const {
00218 return TermIterator(NULL);
00219 }
00220
00224 bool empty() const;
00225
00227 std::string get_description() const;
00228
00229 private:
00230 void add_subquery(const Query & subq);
00231 void add_subquery(const Query * subq);
00232 void add_subquery(const std::string & tname);
00233 void start_construction(Query::op op_, Xapian::termcount parameter);
00234 void end_construction();
00235 void abort_construction();
00236 };
00237
00238 template <class Iterator>
00239 Query::Query(Query::op op_, Iterator qbegin, Iterator qend, termcount parameter)
00240 : internal(0)
00241 {
00242 try {
00243 start_construction(op_, parameter);
00244
00245
00246 while (qbegin != qend) {
00247 add_subquery(*qbegin);
00248 ++qbegin;
00249 }
00250
00251 end_construction();
00252 } catch (...) {
00253 abort_construction();
00254 throw;
00255 }
00256 }
00257
00259 class XAPIAN_VISIBILITY_DEFAULT Query::Internal : public Xapian::Internal::RefCntBase {
00260 friend class ::LocalSubMatch;
00261 friend class ::MultiMatch;
00262 friend class ::QueryOptimiser;
00263 friend struct ::SortPosName;
00264 friend class Query;
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 Xapian::Query::Internal::op_t op;
00277
00279 subquery_list subqs;
00280
00288 Xapian::termcount parameter;
00289
00295 std::string tname;
00296
00298 std::string str_parameter;
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
00332 void validate_query() const;
00333
00339 bool simplify_matchnothing();
00340
00343 static std::string get_op_name(Xapian::Query::Internal::op_t op);
00344
00347 void collapse_subqs();
00348
00352 void flatten_subqs();
00353
00356 std::string serialise(Xapian::termpos & curpos) const;
00357
00358 public:
00360 Internal(const Query::Internal & copyme);
00361
00363 void operator=(const Query::Internal & copyme);
00364
00366 explicit Internal(const std::string & tname_, Xapian::termcount wqf_ = 1,
00367 Xapian::termpos term_pos_ = 0);
00368
00370 Internal(op_t op_, Xapian::termcount parameter);
00371
00373 Internal(op_t op_, Xapian::valueno valno,
00374 const std::string &begin, const std::string &end);
00375
00377 ~Internal();
00378
00379 static Xapian::Query::Internal * unserialise(const std::string &s);
00380
00383 void add_subquery(const Query::Internal * subq);
00384
00385 void set_dbl_parameter(double dbl_parameter_);
00386
00387 double get_dbl_parameter() const;
00388
00391 Query::Internal * end_construction();
00392
00396 std::string serialise() const {
00397 Xapian::termpos curpos = 1;
00398 return serialise(curpos);
00399 }
00400
00402 std::string get_description() const;
00403
00411 Xapian::termcount get_parameter() const { return parameter; }
00412
00417 Xapian::termcount get_length() const;
00418
00424 TermIterator get_terms() const;
00425 };
00426
00427 }
00428
00429 #endif