include/xapian/queryparser.h

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2005,2006 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00019  * USA
00020  */
00021 
00022 #ifndef XAPIAN_INCLUDED_QUERYPARSER_H
00023 #define XAPIAN_INCLUDED_QUERYPARSER_H
00024 
00025 #include <xapian/base.h>
00026 #include <xapian/query.h>
00027 #include <xapian/stem.h>
00028 #include <xapian/termiterator.h>
00029 
00030 #include <set>
00031 #include <string>
00032 
00033 namespace Xapian {
00034 
00036 class Stopper {
00037   public:
00039     virtual bool operator()(const std::string & term) const = 0;
00040 
00042     virtual ~Stopper() { }
00043 
00045     virtual std::string get_description() const;
00046 };
00047 
00049 class SimpleStopper : public Stopper {
00050   private:
00051     std::set<std::string> stop_words;
00052 
00053   public:
00055     SimpleStopper() { }
00056 
00058 #ifndef __SUNPRO_CC
00059     template <class Iterator>
00060     SimpleStopper(Iterator begin, Iterator end) : stop_words(begin, end) { }
00061 #else
00062     // Sun's C++ doesn't cope with the Iterator points to const char *.
00063     template <class Iterator>
00064     SimpleStopper(Iterator begin, Iterator end) {
00065         while (begin != end) stop_words.insert(*begin++);
00066     }
00067 #endif
00068 
00070     void add(const std::string word) { stop_words.insert(word); }
00071 
00073     virtual bool operator()(const std::string & term) const {
00074         return stop_words.find(term) != stop_words.end();
00075     }
00076 
00078     virtual ~SimpleStopper() { }
00079 
00081     virtual std::string get_description() const;
00082 };
00083 
00085 class QueryParser {
00086   public:
00088     class Internal;
00090     Xapian::Internal::RefCntPtr<Internal> internal;
00091 
00093     typedef enum {
00095         FLAG_BOOLEAN = 1,
00097         FLAG_PHRASE = 2,
00099         FLAG_LOVEHATE = 4,
00101         FLAG_BOOLEAN_ANY_CASE = 8,
00103         FLAG_WILDCARD = 16
00104     } feature_flag;
00105 
00106     typedef enum { STEM_NONE, STEM_SOME, STEM_ALL } stem_strategy;
00107 
00109     QueryParser(const QueryParser & o);
00110 
00112     QueryParser & operator=(const QueryParser & o);
00113 
00115     QueryParser();
00116 
00118     ~QueryParser();
00119 
00121     void set_stemmer(const Xapian::Stem & stemmer);
00122 
00124     void set_stemming_strategy(stem_strategy strategy);
00125 
00127     void set_stopper(const Stopper *stop = NULL);
00128 
00146     XAPIAN_DEPRECATED(void set_stemming_options(const std::string &lang, bool stem_all = false,
00147                               const Stopper *stop = NULL));
00148 
00150     void set_default_op(Query::op default_op);
00151 
00153     Query::op get_default_op() const;
00154 
00156     void set_database(const Database &db);
00157 
00165     Query parse_query(const std::string &query_string,
00166                       unsigned flags = FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE);
00167 
00180     void add_prefix(const std::string &field, const std::string &prefix);
00181 
00197     void add_boolean_prefix(const std::string & field, const std::string &prefix);
00198 
00200     TermIterator stoplist_begin() const;
00201     TermIterator stoplist_end() const {
00202         return TermIterator(NULL);
00203     }
00204 
00206     TermIterator unstem_begin(const std::string &term) const;
00207     TermIterator unstem_end(const std::string &) const {
00208         return TermIterator(NULL);
00209     }
00210 
00212     std::string get_description() const;
00213 };
00214 
00215 }
00216 
00217 #endif // XAPIAN_INCLUDED_QUERYPARSER_H

Documentation for Xapian (version 0.9.6).
Generated on 15 May 2006 by Doxygen 1.4.6.