queryparser.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005,2006,2007,2008,2009,2010,2011 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 
64 #if ! defined __SUNPRO_CC || __SUNPRO_CC - 0 >= 0x580
65  template <class Iterator>
66  SimpleStopper(Iterator begin, Iterator end) : stop_words(begin, end) { }
67 #else
68  // Older versions of Sun's C++ compiler don't cope with the Iterator
69  // pointing to const char *.
70  template <class Iterator>
71  SimpleStopper(Iterator begin, Iterator end) {
72  while (begin != end) stop_words.insert(*begin++);
73  }
74 #endif
75 
77  void add(const std::string & word) { stop_words.insert(word); }
78 
79  virtual bool operator()(const std::string & term) const {
80  return stop_words.find(term) != stop_words.end();
81  }
82 
83  virtual std::string get_description() const;
84 };
85 
89  virtual ~ValueRangeProcessor();
90 
105  virtual Xapian::valueno operator()(std::string &begin, std::string &end) = 0;
106 };
107 
113  protected:
115 
116  private:
117  bool prefix;
118  std::string str;
119 
120  public:
126  : valno(slot_), str() { }
127 
136  StringValueRangeProcessor(Xapian::valueno slot_, const std::string &str_,
137  bool prefix_ = true)
138  : valno(slot_), prefix(prefix_), str(str_) { }
139 
154  Xapian::valueno operator()(std::string &begin, std::string &end);
155 };
156 
164 
165  public:
176  DateValueRangeProcessor(Xapian::valueno slot_, bool prefer_mdy_ = false,
177  int epoch_year_ = 1970)
178  : StringValueRangeProcessor(slot_),
179  prefer_mdy(prefer_mdy_), epoch_year(epoch_year_) { }
180 
218  DateValueRangeProcessor(Xapian::valueno slot_, const std::string &str_,
219  bool prefix_ = true,
220  bool prefer_mdy_ = false, int epoch_year_ = 1970)
221  : StringValueRangeProcessor(slot_, str_, prefix_),
222  prefer_mdy(prefer_mdy_), epoch_year(epoch_year_) { }
223 
224 #ifndef SWIG
225 
269  DateValueRangeProcessor(Xapian::valueno slot_, const char * str_,
270  bool prefix_ = true,
271  bool prefer_mdy_ = false, int epoch_year_ = 1970)
272  : StringValueRangeProcessor(slot_, str_, prefix_),
273  prefer_mdy(prefer_mdy_), epoch_year(epoch_year_) { }
274 #endif
275 
291  Xapian::valueno operator()(std::string &begin, std::string &end);
292 };
293 
302  public:
308  : StringValueRangeProcessor(slot_) { }
309 
342  NumberValueRangeProcessor(Xapian::valueno slot_, const std::string &str_,
343  bool prefix_ = true)
344  : StringValueRangeProcessor(slot_, str_, prefix_) { }
345 
363  Xapian::valueno operator()(std::string &begin, std::string &end);
364 };
365 
368  public:
370  class Internal;
373 
375  typedef enum {
377  FLAG_BOOLEAN = 1,
379  FLAG_PHRASE = 2,
381  FLAG_LOVEHATE = 4,
383  FLAG_BOOLEAN_ANY_CASE = 8,
393  FLAG_WILDCARD = 16,
400  FLAG_PURE_NOT = 32,
418  FLAG_PARTIAL = 64,
419 
433  FLAG_SPELLING_CORRECTION = 128,
434 
439  FLAG_SYNONYM = 256,
440 
445  FLAG_AUTO_SYNONYMS = 512,
446 
452  FLAG_AUTO_MULTIWORD_SYNONYMS = 1024 | FLAG_AUTO_SYNONYMS,
453 
461  FLAG_DEFAULT = FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE
462  } feature_flag;
463 
465  typedef enum { STEM_NONE, STEM_SOME, STEM_ALL, STEM_ALL_Z } stem_strategy;
466 
468  QueryParser(const QueryParser & o);
469 
471  QueryParser & operator=(const QueryParser & o);
472 
474  QueryParser();
475 
477  ~QueryParser();
478 
489  void set_stemmer(const Xapian::Stem & stemmer);
490 
511  void set_stemming_strategy(stem_strategy strategy);
512 
518  void set_stopper(const Stopper *stop = NULL);
519 
532  void set_default_op(Query::op default_op);
533 
535  Query::op get_default_op() const;
536 
544  void set_database(const Database &db);
545 
553  void set_max_wildcard_expansion(Xapian::termcount limit);
554 
578  Query parse_query(const std::string &query_string,
579  unsigned flags = FLAG_DEFAULT,
580  const std::string &default_prefix = std::string());
581 
621  void add_prefix(const std::string &field, const std::string &prefix);
622 
675  void add_boolean_prefix(const std::string &field, const std::string &prefix,
676  bool exclusive);
677 
678  /* FIXME:1.3: Merge two versions into one with optional parameter
679  * "exclusive", default true. */
680  void add_boolean_prefix(const std::string &field, const std::string &prefix);
681 
683  TermIterator stoplist_begin() const;
685  return TermIterator();
686  }
687 
689  TermIterator unstem_begin(const std::string &term) const;
690  TermIterator unstem_end(const std::string &) const {
691  return TermIterator();
692  }
693 
695  void add_valuerangeprocessor(Xapian::ValueRangeProcessor * vrproc);
696 
704  std::string get_corrected_query_string() const;
705 
707  std::string get_description() const;
708 };
709 
737 std::string sortable_serialise(double value);
738 
754 double sortable_unserialise(const std::string & value);
755 
756 }
757 
758 #endif // XAPIAN_INCLUDED_QUERYPARSER_H

Documentation for Xapian (version 1.2.17).
Generated on Wed Jan 29 2014 by Doxygen 1.8.1.2.