2 * @brief The non-lemon-generated parts of the QueryParser class.
4 /* Copyright (C) 2005,2006,2007,2010,2011,2012,2013,2015,2016,2019 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
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>
39 typedef enum { NON_BOOLEAN
, BOOLEAN
, BOOLEAN_EXCLUSIVE
} filter_type
;
41 /** Information about how to handle a field prefix in the query string. */
43 /// The type of this field.
48 /// Field prefix strings.
49 vector
<string
> prefixes
;
51 /// Field processor. Currently only one is supported.
52 Xapian::Internal::opt_intrusive_ptr
<Xapian::FieldProcessor
> proc
;
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_
), proc(proc_
)
73 Xapian::Internal::opt_intrusive_ptr
<RangeProcessor
> proc
;
75 bool default_grouping
;
77 RangeProc(RangeProcessor
* range_proc
, const std::string
* grouping_
)
79 grouping(grouping_
? *grouping_
: std::string()),
80 default_grouping(grouping_
== NULL
) { }
83 class QueryParser::Internal
: public Xapian::Internal::intrusive_base
{
84 friend class QueryParser
;
87 stem_strategy stem_action
;
88 Xapian::Internal::opt_intrusive_ptr
<const Stopper
> stopper
;
92 list
<string
> stoplist
;
93 multimap
<string
, string
> unstem
;
95 // Map "from" -> "A" ; "subject" -> "C" ; "newsgroups" -> "G" ;
96 // "foobar" -> "XFOO". FIXME: it does more than this now!
97 map
<string
, FieldInfo
> field_map
;
99 list
<RangeProc
> rangeprocs
;
101 string corrected_query
;
103 Xapian::termcount max_wildcard_expansion
;
105 Xapian::termcount max_partial_expansion
;
107 int max_wildcard_type
;
109 int max_partial_type
;
111 void add_prefix(const string
&field
, const string
&prefix
);
113 void add_prefix(const string
&field
, Xapian::FieldProcessor
*proc
);
115 void add_boolean_prefix(const string
&field
, const string
&prefix
,
116 const string
* grouping
);
118 void add_boolean_prefix(const string
&field
, Xapian::FieldProcessor
*proc
,
119 const string
* grouping
);
121 std::string
parse_term(Utf8Iterator
&it
, const Utf8Iterator
&end
,
122 bool cjk_ngram
, bool &is_cjk_term
,
126 Internal() : stem_action(STEM_SOME
), stopper(NULL
),
127 default_op(Query::OP_OR
), errmsg(NULL
),
128 max_wildcard_expansion(0), max_partial_expansion(100),
129 max_wildcard_type(Xapian::Query::WILDCARD_LIMIT_ERROR
),
130 max_partial_type(Xapian::Query::WILDCARD_LIMIT_MOST_FREQUENT
) { }
132 Query
parse_query(const string
& query_string
, unsigned int flags
, const string
& default_prefix
);
137 #endif // XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H