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 empty() const;
00213
00215 bool is_empty()
const {
return empty(); }
00216
00220 std::string
get_description() const;
00221
00222 private:
00223
void add_subquery(const
Query & subq);
00224
void add_subquery(const
Query * subq);
00225
void add_subquery(const std::string & tname);
00226
void start_construction(
Query::op op_);
00227
void end_construction();
00228
void abort_construction();
00229 };
00230
00231 template <class Iterator>
00232 Query::
Query(
Query::op op_, Iterator qbegin, Iterator qend) : internal(0)
00233 {
00234
try {
00235 start_construction(op_);
00236
00237
00238
while (qbegin != qend) {
00239 add_subquery(*qbegin);
00240 ++qbegin;
00241 }
00242
00243 end_construction();
00244 }
catch (...) {
00245 abort_construction();
00246
throw;
00247 }
00248 }
00249
00250
template <
class SubQ>
00251 Query::Query(Query::op op_, SubQ q) :
internal(0)
00252 {
00253
try {
00254 start_construction(op_);
00255 add_subquery(q);
00256 end_construction();
00257 }
catch (...) {
00258 abort_construction();
00259
throw;
00260 }
00261 }
00262
00264 class Query::Internal :
public Xapian::
Internal::RefCntBase {
00265
friend class ::MultiMatch;
00266
friend class ::LocalSubMatch;
00267
friend class ::SortPosName;
00268
public:
00269
static const int OP_LEAF = -1;
00270
00272 typedef std::vector<Internal *>
subquery_list;
00273
00275 typedef int op_t;
00276
00277
private:
00279
op_t op;
00280
00282
subquery_list subqs;
00283
00285 Xapian::termcount qlen;
00286
00290 Xapian::termpos window;
00291
00294
double cutoff;
00295
00298 Xapian::termcount elite_set_size;
00299
00301 std::string tname;
00302
00304 Xapian::termpos term_pos;
00305
00307 Xapian::termcount wqf;
00308
00316
void swap(
Query::Internal &other);
00317
00319
void initialise_from_copy(
const Query::Internal & copyme);
00320
00321
void accumulate_terms(
00322 std::vector<std::pair<std::string, Xapian::termpos> > &terms)
const;
00323
00328
Internal * simplify_query();
00329
00334
void prevalidate_query() const;
00335
00343
void validate_query() const;
00344
00347 static std::string get_op_name(Xapian::
Query::
Internal::
op_t op);
00348
00351
void collapse_subqs();
00352
00356
void flatten_subqs();
00357
00358 public:
00360
Internal(const
Query::
Internal & copyme);
00361
00363
void operator=(const
Query::
Internal & copyme);
00364
00366
Internal(const std::string & tname_, Xapian::
termcount wqf_ = 1,
00367 Xapian::
termpos term_pos_ = 0);
00368
00370
Internal(
op_t op_);
00371
00373 ~
Internal();
00374
00375 static Xapian::
Query::
Internal * unserialise(const std::string &s);
00376
00379
void add_subquery(const
Query::
Internal & subq);
00380
00383
Query::
Internal * end_construction();
00384
00388 std::string serialise() const;
00389
00393 std::string get_description() const;
00394
00396
void set_window(Xapian::
termpos window);
00397
00399
void set_cutoff(
double cutoff);
00400
00402
void set_elite_set_size(Xapian::
termcount size);
00403
00408 Xapian::
termcount get_length()
const {
return qlen; }
00409
00415 Xapian::termcount
set_length(Xapian::termcount qlen_);
00416
00422
TermIterator get_terms() const;
00423 };
00424
00425 }
00426
00427 #endif