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,
403  FLAG_WILDCARD = 16,
410  FLAG_PURE_NOT = 32,
428  FLAG_PARTIAL = 64,
429 
443  FLAG_SPELLING_CORRECTION = 128,
444 
449  FLAG_SYNONYM = 256,
450 
455  FLAG_AUTO_SYNONYMS = 512,
456 
462  FLAG_AUTO_MULTIWORD_SYNONYMS = 1024 | FLAG_AUTO_SYNONYMS,
463 
471  FLAG_DEFAULT = FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE
472  } feature_flag;
473 
475  typedef enum { STEM_NONE, STEM_SOME, STEM_ALL, STEM_ALL_Z } stem_strategy;
476 
478  QueryParser(const QueryParser & o);
479 
481  QueryParser & operator=(const QueryParser & o);
482 
484  QueryParser();
485 
487  ~QueryParser();
488 
499  void set_stemmer(const Xapian::Stem & stemmer);
500 
520  void set_stemming_strategy(stem_strategy strategy);
521 
527  void set_stopper(const Stopper *stop = NULL);
528 
541  void set_default_op(Query::op default_op);
542 
544  Query::op get_default_op() const;
545 
553  void set_database(const Database &db);
554 
562  void set_max_wildcard_expansion(Xapian::termcount limit);
563 
587  Query parse_query(const std::string &query_string,
588  unsigned flags = FLAG_DEFAULT,
589  const std::string &default_prefix = std::string());
590 
630  void add_prefix(const std::string &field, const std::string &prefix);
631 
684  void add_boolean_prefix(const std::string &field, const std::string &prefix,
685  bool exclusive);
686 
687  /* FIXME:1.3: Merge two versions into one with optional parameter
688  * "exclusive", default true. */
689  void add_boolean_prefix(const std::string &field, const std::string &prefix);
690 
692  TermIterator stoplist_begin() const;
694  return TermIterator();
695  }
696 
698  TermIterator unstem_begin(const std::string &term) const;
699  TermIterator unstem_end(const std::string &) const {
700  return TermIterator();
701  }
702 
704  void add_valuerangeprocessor(Xapian::ValueRangeProcessor * vrproc);
705 
713  std::string get_corrected_query_string() const;
714 
716  std::string get_description() const;
717 };
718 
746 std::string sortable_serialise(double value);
747 
763 double sortable_unserialise(const std::string & value);
764 
765 }
766 
767 #endif // XAPIAN_INCLUDED_QUERYPARSER_H

Documentation for Xapian (version 1.2.21).
Generated on Thu May 21 2015 by Doxygen 1.8.1.2.