2 * @brief The non-lemon-generated parts of the QueryParser class.
4 /* Copyright (C) 2005-2023 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>
37 typedef enum { NON_BOOLEAN
, BOOLEAN
, BOOLEAN_EXCLUSIVE
} filter_type
;
39 /** Information about how to handle a field prefix in the query string. */
41 /// The type of this field.
46 /// Field prefix strings.
47 std::vector
<std::string
> prefixes
;
49 /// Field processor. Currently only one is supported.
50 Xapian::Internal::opt_intrusive_ptr
<Xapian::FieldProcessor
> proc
;
52 FieldInfo(filter_type type_
, const std::string
& prefix
,
53 const std::string
& grouping_
= std::string())
54 : type(type_
), grouping(grouping_
)
56 prefixes
.push_back(prefix
);
59 FieldInfo(filter_type type_
, Xapian::FieldProcessor
* proc_
,
60 const std::string
& grouping_
= std::string())
61 : type(type_
), grouping(grouping_
), proc(proc_
)
71 Xapian::Internal::opt_intrusive_ptr
<RangeProcessor
> proc
;
73 bool default_grouping
;
75 RangeProc(RangeProcessor
* range_proc
, const std::string
* grouping_
)
77 grouping(grouping_
? *grouping_
: std::string()),
78 default_grouping(grouping_
== NULL
) { }
81 class QueryParser::Internal
: public Xapian::Internal::intrusive_base
{
82 friend class QueryParser
;
85 stem_strategy stem_action
= STEM_SOME
;
86 Xapian::Internal::opt_intrusive_ptr
<const Stopper
> stopper
;
87 Query::op default_op
= Query::OP_OR
;
88 const char* errmsg
= nullptr;
90 std::list
<std::string
> stoplist
;
91 std::multimap
<std::string
, std::string
> unstem
;
93 // Map "from" -> "A" ; "subject" -> "C" ; "newsgroups" -> "G" ;
94 // "foobar" -> "XFOO". FIXME: it does more than this now!
95 std::map
<std::string
, FieldInfo
> field_map
;
97 std::list
<RangeProc
> rangeprocs
;
99 std::string corrected_query
;
101 Xapian::termcount max_wildcard_expansion
= 0;
103 Xapian::termcount max_partial_expansion
= 100;
105 Xapian::termcount max_fuzzy_expansion
= 0;
107 int max_wildcard_type
= Xapian::Query::WILDCARD_LIMIT_ERROR
;
109 int max_partial_type
= Xapian::Query::WILDCARD_LIMIT_MOST_FREQUENT
;
111 int max_fuzzy_type
= Xapian::Query::WILDCARD_LIMIT_ERROR
;
113 unsigned min_wildcard_prefix_len
= 0;
115 unsigned min_partial_prefix_len
= 2;
117 void add_prefix(const std::string
& field
, const std::string
& prefix
);
119 void add_prefix(const std::string
& field
, Xapian::FieldProcessor
* proc
);
121 void add_boolean_prefix(const std::string
& field
,
122 const std::string
& prefix
,
123 const std::string
* grouping
);
125 void add_boolean_prefix(const std::string
& field
,
126 Xapian::FieldProcessor
* proc
,
127 const std::string
* grouping
);
129 std::string
parse_term(Utf8Iterator
& it
, const Utf8Iterator
& end
,
130 bool try_word_break
, unsigned flags
,
131 bool& needs_word_break
, bool& was_acronym
,
132 size_t& first_wildcard
,
134 unsigned& edit_distance
);
139 Query
parse_query(const std::string
& query_string
,
141 const std::string
& default_prefix
);
146 #endif // XAPIAN_INCLUDED_QUERYPARSER_INTERNAL_H