Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

include/xapian/queryparser.h

Go to the documentation of this file.
00001 00004 /* Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 }; 00044 00046 class SimpleStopper : public Stopper { 00047 private: 00048 std::set<std::string> stop_words; 00049 00050 public: 00052 SimpleStopper() { } 00053 00055 #ifndef __SUNPRO_CC 00056 template <class Iterator> 00057 SimpleStopper(Iterator begin, Iterator end) : stop_words(begin, end) { } 00058 #else 00059 // Sun's C++ doesn't cope with the Iterator points to const char *. 00060 template <class Iterator> 00061 SimpleStopper(Iterator begin, Iterator end) { 00062 while (begin != end) stop_words.insert(*begin++); 00063 } 00064 #endif 00065 00067 void add(const std::string word) { stop_words.insert(word); } 00068 00070 virtual bool operator()(const std::string & term) const { 00071 return stop_words.find(term) != stop_words.end(); 00072 } 00073 00075 virtual ~SimpleStopper() { } 00076 }; 00077 00079 class QueryParser { 00080 public: 00082 class Internal; 00084 Xapian::Internal::RefCntPtr<Internal> internal; 00085 00087 typedef enum { 00088 FLAG_BOOLEAN = 1, 00089 FLAG_PHRASE = 2, 00090 FLAG_LOVEHATE = 4 00091 } feature_flag; 00092 00093 typedef enum { STEM_NONE, STEM_SOME, STEM_ALL } stem_strategy; 00094 00096 QueryParser(const QueryParser & o); 00097 00099 QueryParser & operator=(const QueryParser & o); 00100 00102 QueryParser(); 00103 00105 ~QueryParser(); 00106 00108 void set_stemmer(const Xapian::Stem & stemmer); 00109 00111 void set_stemming_strategy(stem_strategy strategy); 00112 00114 void set_stopper(const Stopper *stop = NULL); 00115 00117 void set_stemming_options(const std::string &lang, bool stem_all = false, 00118 const Stopper *stop = NULL) { 00119 set_stemmer(Xapian::Stem(lang)); 00120 if (lang.empty() || lang == "none") { 00121 set_stemming_strategy(STEM_NONE); 00122 } else { 00123 set_stemming_strategy(stem_all ? STEM_ALL : STEM_SOME); 00124 } 00125 set_stopper(stop); 00126 } 00127 00129 void set_default_op(Query::op default_op); 00130 00132 Query::op get_default_op() const; 00133 00135 void set_database(const Database &db); 00136 00138 Query parse_query(const std::string &query_string); 00139 00140 void add_prefix(const std::string &field, const std::string &prefix); 00141 00142 void add_boolean_prefix(const std::string & field, const std::string &prefix); 00143 00144 TermIterator stoplist_begin() const; 00145 TermIterator stoplist_end() const { 00146 return TermIterator(NULL); 00147 } 00148 00149 TermIterator unstem_begin(const std::string &term) const; 00150 TermIterator unstem_end(const std::string &) const { 00151 return TermIterator(NULL); 00152 } 00153 00155 std::string get_description() const; 00156 }; 00157 00158 } 00159 00160 #endif // XAPIAN_INCLUDED_QUERYPARSER_H

Documentation for Xapian (version 0.9.0).
Generated on 13 May 2005 by Doxygen 1.3.8.