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
00100
OP_ELITE_SET = 10
00101 } op;
00102
00104
Query(
const Query & copyme);
00105
00107
Query &
operator=(
const Query & copyme);
00108
00117
Query();
00118
00120
~Query();
00121
00123
Query(
const std::string & tname_, Xapian::termcount wqf_ = 1,
00124 Xapian::termpos pos_ = 0);
00125
00127
Query(Query::op op_,
const Query & left,
const Query & right);
00128
00130
Query(Query::op op_,
00131
const std::string & left,
const std::string & right);
00132
00148
template <
class Iterator>
00149
Query(Query::op op_, Iterator qbegin, Iterator qend,
00150 Xapian::termcount parameter = 0);
00151
00153
Query(Query::op op_,
Xapian::Query q);
00154
00159 Xapian::termcount
get_length() const;
00160
00166
TermIterator get_terms_begin() const;
00167
00171
TermIterator get_terms_end() const;
00172
00176
bool empty() const;
00177
00179 bool is_empty()
const {
return empty(); }
00180
00184 std::string
get_description() const;
00185
00186 private:
00187
void add_subquery(const
Query & subq);
00188
void add_subquery(const
Query * subq);
00189
void add_subquery(const std::string & tname);
00190
void start_construction(
Query::op op_, Xapian::
termcount parameter);
00191
void end_construction();
00192
void abort_construction();
00193 };
00194
00195 template <class Iterator>
00196 Query::
Query(
Query::op op_, Iterator qbegin, Iterator qend,
termcount parameter)
00197 : internal(0)
00198 {
00199
try {
00200 start_construction(op_, parameter);
00201
00202
00203
while (qbegin != qend) {
00204 add_subquery(*qbegin);
00205 ++qbegin;
00206 }
00207
00208 end_construction();
00209 }
catch (...) {
00210 abort_construction();
00211
throw;
00212 }
00213 }
00214
00216 class Query::Internal :
public Xapian::
Internal::RefCntBase {
00217
friend class ::MultiMatch;
00218
friend class ::LocalSubMatch;
00219
friend class ::SortPosName;
00220
public:
00221
static const int OP_LEAF = -1;
00222
00224 typedef std::vector<Internal *>
subquery_list;
00225
00227 typedef int op_t;
00228
00229
private:
00231
op_t op;
00232
00234
subquery_list subqs;
00235
00241 Xapian::termcount parameter;
00242
00244 std::string tname;
00245
00247 Xapian::termpos term_pos;
00248
00250 Xapian::termcount wqf;
00251
00259
void swap(
Query::Internal &other);
00260
00262
void initialise_from_copy(
const Query::Internal & copyme);
00263
00264
void accumulate_terms(
00265 std::vector<std::pair<std::string, Xapian::termpos> > &terms)
const;
00266
00271
Internal * simplify_query();
00272
00277
void prevalidate_query() const;
00278
00286
void validate_query() const;
00287
00290 static std::string get_op_name(Xapian::
Query::
Internal::
op_t op);
00291
00294
void collapse_subqs();
00295
00299
void flatten_subqs();
00300
00301 public:
00303
Internal(const
Query::
Internal & copyme);
00304
00306
void operator=(const
Query::
Internal & copyme);
00307
00309
Internal(const std::string & tname_, Xapian::
termcount wqf_ = 1,
00310 Xapian::
termpos term_pos_ = 0);
00311
00313
Internal(
op_t op_, Xapian::
termcount parameter);
00314
00316 ~
Internal();
00317
00318 static Xapian::
Query::
Internal * unserialise(const std::string &s);
00319
00322
void add_subquery(const
Query::
Internal & subq);
00323
00326
Query::
Internal * end_construction();
00327
00331 std::string serialise() const;
00332
00336 std::string get_description() const;
00337
00342 Xapian::
termcount get_length() const;
00343
00349
TermIterator get_terms() const;
00350 };
00351
00352 }
00353
00354 #endif