queryparser.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005,2006,2007,2008,2009,2010,2011,2014 Olly Betts
5  * Copyright (C) 2010 Adam Sj√łgren
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #ifndef XAPIAN_INCLUDED_QUERYPARSER_H
24 #define XAPIAN_INCLUDED_QUERYPARSER_H
25 
26 #include <xapian/base.h>
27 #include <xapian/query.h>
28 #include <xapian/termiterator.h>
29 #include <xapian/visibility.h>
30 
31 #include <set>
32 #include <string>
33 
34 namespace Xapian {
35 
36 class Database;
37 class Stem;
38 
41  public:
46  virtual bool operator()(const std::string & term) const = 0;
47 
49  virtual ~Stopper() { }
50 
52  virtual std::string get_description() const;
53 };
54 
57  std::set<std::string> stop_words;
58 
59  public:
62 
72 #if ! defined __SUNPRO_CC || __SUNPRO_CC - 0 >= 0x580
73  template <class Iterator>
74  SimpleStopper(Iterator begin, Iterator end) : stop_words(begin, end) { }
75 #else
76  // Older versions of Sun's C++ compiler don't cope with the Iterator
77  // pointing to const char *.
78  template <class Iterator>
79  SimpleStopper(Iterator begin, Iterator end) {
80  while (begin != end) stop_words.insert(*begin++);
81  }
82 #endif
83 
85  void add(const std::string & word) { stop_words.insert(word); }
86 
87  virtual bool operator()(const std::string & term) const {
88  return stop_words.find(term) != stop_words.end();
89  }
90 
91  virtual std::string get_description() const;
92 };
93 
97  virtual ~ValueRangeProcessor();
98 
113  virtual Xapian::valueno operator()(std::string &begin, std::string &end) = 0;
114 };
115 
121  protected:
123 
124  private:
125  bool prefix;
126  std::string str;
127 
128  public:
134  : valno(slot_), str() { }
135 
144  StringValueRangeProcessor(Xapian::valueno slot_, const std::string &str_,
145  bool prefix_ = true)
146  : valno(slot_), prefix(prefix_), str(str_) { }
147 
162  Xapian::valueno operator()(std::string &begin, std::string &end);
163 };
164 
172 
173  public:
184  DateValueRangeProcessor(Xapian::valueno slot_, bool prefer_mdy_ = false,
185  int epoch_year_ = 1970)
186  : StringValueRangeProcessor(slot_),
187  prefer_mdy(prefer_mdy_), epoch_year(epoch_year_) { }
188 
226  DateValueRangeProcessor(Xapian::valueno slot_, const std::string &str_,
227  bool prefix_ = true,
228  bool prefer_mdy_ = false, int epoch_year_ = 1970)
229  : StringValueRangeProcessor(slot_, str_, prefix_),
230  prefer_mdy(prefer_mdy_), epoch_year(epoch_year_) { }
231 
232 #ifndef SWIG
233 
277  DateValueRangeProcessor(Xapian::valueno slot_, const char * str_,
278  bool prefix_ = true,
279  bool prefer_mdy_ = false, int epoch_year_ = 1970)
280  : StringValueRangeProcessor(slot_, str_, prefix_),
281  prefer_mdy(prefer_mdy_), epoch_year(epoch_year_) { }
282 #endif
283 
299  Xapian::valueno operator()(std::string &begin, std::string &end);
300 };
301 
310  public:
316  : StringValueRangeProcessor(slot_) { }
317 
350  NumberValueRangeProcessor(Xapian::valueno slot_, const std::string &str_,
351  bool prefix_ = true)
352  : StringValueRangeProcessor(slot_, str_, prefix_) { }
353 
371  Xapian::valueno operator()(std::string &begin, std::string &end);
372 };
373 
376  public:
378  class Internal;
381 
383  typedef enum {
385  FLAG_BOOLEAN = 1,
387  FLAG_PHRASE = 2,
389  FLAG_LOVEHATE = 4,
391  FLAG_BOOLEAN_ANY_CASE = 8,
401  FLAG_WILDCARD = 16,
408  FLAG_PURE_NOT = 32,
426  FLAG_PARTIAL = 64,
427 
441  FLAG_SPELLING_CORRECTION = 128,
442 
447  FLAG_SYNONYM = 256,
448 
453  FLAG_AUTO_SYNONYMS = 512,
454 
460  FLAG_AUTO_MULTIWORD_SYNONYMS = 1024 | FLAG_AUTO_SYNONYMS,
461 
469  FLAG_DEFAULT = FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE
470  } feature_flag;
471 
473  typedef enum { STEM_NONE, STEM_SOME, STEM_ALL, STEM_ALL_Z } stem_strategy;
474 
476  QueryParser(const QueryParser & o);
477 
479  QueryParser & operator=(const QueryParser & o);
480 
482  QueryParser();
483 
485  ~QueryParser();
486 
497  void set_stemmer(const Xapian::Stem & stemmer);
498 
518  void set_stemming_strategy(stem_strategy strategy);
519 
525  void set_stopper(const Stopper *stop = NULL);
526 
539  void set_default_op(Query::op default_op);
540 
542  Query::op get_default_op() const;
543 
551  void set_database(const Database &db);
552 
560  void set_max_wildcard_expansion(Xapian::termcount limit);
561 
585  Query parse_query(const std::string &query_string,
586  unsigned flags = FLAG_DEFAULT,
587  const std::string &default_prefix = std::string());
588 
628  void add_prefix(const std::string &field, const std::string &prefix);
629 
682  void add_boolean_prefix(const std::string &field, const std::string &prefix,
683  bool exclusive);
684 
685  /* FIXME:1.3: Merge two versions into one with optional parameter
686  * "exclusive", default true. */
687  void add_boolean_prefix(const std::string &field, const std::string &prefix);
688 
690  TermIterator stoplist_begin() const;
692  return TermIterator();
693  }
694 
696  TermIterator unstem_begin(const std::string &term) const;
697  TermIterator unstem_end(const std::string &) const {
698  return TermIterator();
699  }
700 
702  void add_valuerangeprocessor(Xapian::ValueRangeProcessor * vrproc);
703 
711  std::string get_corrected_query_string() const;
712 
714  std::string get_description() const;
715 };
716 
744 std::string sortable_serialise(double value);
745 
761 double sortable_unserialise(const std::string & value);
762 
763 }
764 
765 #endif // XAPIAN_INCLUDED_QUERYPARSER_H

Documentation for Xapian (version 1.2.19).
Generated on Tue Oct 21 2014 by Doxygen 1.8.1.2.