[ci] Enable IRC notifications from travis
[xapian.git] / xapian-core / queryparser / queryparser_internal.h
blob832453b9595e32985336258d82e57f92549f798e
1 /** @file queryparser_internal.h
2 * @brief The non-lemon-generated parts of the QueryParser class.
3 */
4 /* Copyright (C) 2005,2006,2007,2010,2011,2012,2013,2015,2016 Olly Betts
5 * Copyright (C) 2010 Adam Sjøgren
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.
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.
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
23 #ifndef XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H
24 #define XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H
26 #include "xapian/intrusive_ptr.h"
27 #include <xapian/database.h>
28 #include <xapian/query.h>
29 #include <xapian/queryparser.h>
30 #include <xapian/stem.h>
32 #include <list>
33 #include <map>
35 using namespace std;
37 class State;
39 typedef enum { NON_BOOLEAN, BOOLEAN, BOOLEAN_EXCLUSIVE } filter_type;
41 /** Information about how to handle a field prefix in the query string. */
42 struct FieldInfo {
43 /// The type of this field.
44 filter_type type;
46 string grouping;
48 /// Field prefix strings.
49 list<string> prefixes;
51 /// Field processors. Currently only one is supported.
52 list<Xapian::Internal::opt_intrusive_ptr<Xapian::FieldProcessor> > procs;
54 FieldInfo(filter_type type_, const string& prefix,
55 const string& grouping_ = string())
56 : type(type_), grouping(grouping_)
58 prefixes.push_back(prefix);
61 FieldInfo(filter_type type_, Xapian::FieldProcessor* proc,
62 const string& grouping_ = string())
63 : type(type_), grouping(grouping_)
65 procs.push_back(proc);
69 namespace Xapian {
71 class Utf8Iterator;
73 struct RangeProc {
74 Xapian::Internal::opt_intrusive_ptr<RangeProcessor> proc;
75 std::string grouping;
76 bool default_grouping;
78 RangeProc(RangeProcessor * range_proc, const std::string* grouping_)
79 : proc(range_proc),
80 grouping(grouping_ ? *grouping_ : std::string()),
81 default_grouping(grouping_ == NULL) { }
84 class QueryParser::Internal : public Xapian::Internal::intrusive_base {
85 friend class QueryParser;
86 friend class ::State;
87 Stem stemmer;
88 stem_strategy stem_action;
89 Xapian::Internal::opt_intrusive_ptr<const Stopper> stopper;
90 Query::op default_op;
91 const char * errmsg;
92 Database db;
93 list<string> stoplist;
94 multimap<string, string> unstem;
96 // Map "from" -> "A" ; "subject" -> "C" ; "newsgroups" -> "G" ;
97 // "foobar" -> "XFOO". FIXME: it does more than this now!
98 map<string, FieldInfo> field_map;
100 list<RangeProc> rangeprocs;
102 string corrected_query;
104 Xapian::termcount max_wildcard_expansion;
106 Xapian::termcount max_partial_expansion;
108 int max_wildcard_type;
110 int max_partial_type;
112 void add_prefix(const string &field, const string &prefix);
114 void add_prefix(const string &field, Xapian::FieldProcessor *proc);
116 void add_boolean_prefix(const string &field, const string &prefix,
117 const string* grouping);
119 void add_boolean_prefix(const string &field, Xapian::FieldProcessor *proc,
120 const string* grouping);
122 std::string parse_term(Utf8Iterator &it, const Utf8Iterator &end,
123 bool cjk_ngram, bool &is_cjk_term,
124 bool &was_acronym);
126 public:
127 Internal() : stem_action(STEM_SOME), stopper(NULL),
128 default_op(Query::OP_OR), errmsg(NULL),
129 max_wildcard_expansion(0), max_partial_expansion(100),
130 max_wildcard_type(Xapian::Query::WILDCARD_LIMIT_ERROR),
131 max_partial_type(Xapian::Query::WILDCARD_LIMIT_MOST_FREQUENT) { }
133 Query parse_query(const string & query_string, unsigned int flags, const string & default_prefix);
138 #endif // XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H