Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/include/om/omquery.h

00001 /* omquery.h
00002  *
00003  * ----START-LICENCE----
00004  * Copyright 1999,2000,2001 BrightStation PLC
00005  * Copyright 2002 Ananova Ltd
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020  * USA
00021  * -----END-LICENCE-----
00022  */
00023 
00024 #ifndef OM_HGUARD_OMQUERY_H
00025 #define OM_HGUARD_OMQUERY_H
00026 
00027 #ifndef OM_HGUARD_OMTYPES_H
00028 #include "om/omtypes.h"
00029 #endif
00030 #ifndef OM_HGUARD_OMTERMLISTITERATOR_H
00031 #include "om/omtermlistiterator.h"
00032 #endif
00033 
00035 // OmQuery class
00036 // =============
00037 // Representation of a query
00038 
00042 class OmQuery {
00043     public:
00045         class Internal;
00047         Internal *internal;
00048 
00050         typedef enum {
00052             OP_AND,
00053 
00055             OP_OR,
00056 
00058             OP_AND_NOT,
00059 
00061             OP_XOR,
00062 
00064             OP_AND_MAYBE,
00065 
00067             OP_FILTER,
00068 
00077             OP_NEAR,
00078 
00087             OP_PHRASE,
00088 
00095             OP_WEIGHT_CUTOFF,
00096 
00100             OP_ELITE_SET
00101         } op;
00102 
00104         OmQuery(const OmQuery & copyme);
00105 
00107         OmQuery & operator=(const OmQuery & copyme);
00108 
00117         OmQuery();
00118 
00120         ~OmQuery();
00121 
00123         OmQuery(const om_termname & tname_,
00124                 om_termcount wqf_ = 1,
00125                 om_termpos term_pos_ = 0);
00126 
00128         OmQuery(OmQuery::op op_, const OmQuery & left, const OmQuery & right);
00129 
00130         /* A query consisting of two subquery pointers, opp-ed together. */
00131         // Don't have this because vector iterators are often implemented as
00132         // simple pointers, so this would override the template class and
00133         // produce unexpected results.  Only plausible solution we can think
00134         // of so far is to change to using construction methods (eg,
00135         // static OmQuery::create_vector(op, begin, end) and
00136         // static OmQuery::create_pair(op, begin, end)
00137         //OmQuery(OmQuery::op op_, const OmQuery * left, const OmQuery * right);
00138 
00140         OmQuery(OmQuery::op op_,
00141                 const om_termname & left, const om_termname & right);
00142 
00153         template <class Iterator>
00154         OmQuery(OmQuery::op op_, Iterator qbegin, Iterator qend);
00155 
00161         template <class SubQ>
00162         OmQuery(OmQuery::op op_, SubQ q);
00163 
00166         void set_window(om_termpos window);
00167 
00170         void set_cutoff(om_weight cutoff);
00171 
00173         void set_elite_set_size(om_termcount size);
00174 
00179         om_termcount get_length() const;
00180 
00186         om_termcount set_length(om_termcount qlen);
00187 
00193         OmTermIterator get_terms_begin() const;
00194 
00198         OmTermIterator get_terms_end() const;
00199 
00201         //  an empty iterator ctor)
00202         bool is_empty() const;
00203                 
00207         std::string get_description() const;
00208 
00209     private:
00210         void add_subquery(const OmQuery & subq);
00211         void add_subquery(const OmQuery * subq);
00212         void add_subquery(const om_termname & tname);
00213         void start_construction(OmQuery::op op_);
00214         void end_construction();
00215         void abort_construction();
00216 };
00217 
00218 template <class Iterator>
00219 OmQuery::OmQuery(OmQuery::op op_, Iterator qbegin, Iterator qend) : internal(0)
00220 {
00221     try {
00222         start_construction(op_);
00223 
00224         /* Add all the elements */
00225         while (qbegin != qend) {
00226             add_subquery(*qbegin);
00227             ++qbegin;
00228         }
00229 
00230         end_construction();
00231     } catch (...) {
00232         abort_construction();
00233         throw;
00234     }
00235 }
00236 
00237 template <class SubQ>
00238 OmQuery::OmQuery(OmQuery::op op_, SubQ q) : internal(0)
00239 {
00240     try {
00241         start_construction(op_);
00242         add_subquery(q);
00243         end_construction();
00244     } catch (...) {
00245         abort_construction();
00246         throw;
00247     }
00248 }
00249 
00250 inline
00251 OmQuery::OmQuery(OmQuery::op op_,
00252                  const om_termname & left,
00253                  const om_termname & right) : internal(0)
00254 {
00255     try {
00256         start_construction(op_);
00257         add_subquery(left);
00258         add_subquery(right);
00259         end_construction();
00260     } catch (...) {
00261         abort_construction();
00262         throw;
00263     }
00264 }
00265 
00266 #endif /* OM_HGUARD_OMQUERY_H */
00267 

Documentation for Xapian (version 0.4.1cvs).
Generated on 20 Sep 2002 by Doxygen 1.2.15.