diff --git a/search-xapian/XS/QueryParser.xs b/search-xapian/XS/QueryParser.xs
index 3bec548..fbc9ca9 100644
a
|
b
|
QueryParser::set_database(database)
|
49 | 49 | CODE: |
50 | 50 | THIS->set_database(*database); |
51 | 51 | |
| 52 | void |
| 53 | QueryParser::set_max_wildcard_expansion(max) |
| 54 | termcount max |
| 55 | CODE: |
| 56 | THIS->set_max_wildcard_expansion(max); |
| 57 | |
52 | 58 | Query * |
53 | 59 | QueryParser::parse_query(q, flags = 7) |
54 | 60 | string q |
diff --git a/search-xapian/Xapian/QueryParser.pm b/search-xapian/Xapian/QueryParser.pm
index f48a12e..3778be3 100644
a
|
b
|
prefix The term prefix to map this to
|
150 | 150 | |
151 | 151 | Returns a string describing this object. |
152 | 152 | |
| 153 | =item set_max_wildcard_expansion <max> |
| 154 | |
| 155 | If the queryparser expands a wildcard to more than max terms, an |
| 156 | exception will be thrown. |
| 157 | |
| 158 | =cut |
| 159 | |
153 | 160 | =back |
154 | 161 | |
155 | 162 | =head1 REFERENCE |
diff --git a/xapian-core/include/xapian/queryparser.h b/xapian-core/include/xapian/queryparser.h
index b03a295..1c79b27 100644
a
|
b
|
class XAPIAN_VISIBILITY_DEFAULT QueryParser {
|
355 | 355 | /// Specify the database being searched. |
356 | 356 | void set_database(const Database &db); |
357 | 357 | |
| 358 | /// Specify the maximum expansion of a wildcard term. |
| 359 | void set_max_wildcard_expansion(Xapian::termcount); |
| 360 | |
358 | 361 | /** Parse a query. |
359 | 362 | * |
360 | 363 | * @param query_string A free-text query as entered by a user |
diff --git a/xapian-core/queryparser/queryparser.cc b/xapian-core/queryparser/queryparser.cc
index 9d9f2df..684733d 100644
a
|
b
|
QueryParser::set_database(const Database &db) {
|
104 | 104 | internal->db = db; |
105 | 105 | } |
106 | 106 | |
| 107 | void |
| 108 | QueryParser::set_max_wildcard_expansion(Xapian::termcount max) |
| 109 | { |
| 110 | internal->max_wildcard_expansion = max; |
| 111 | } |
| 112 | |
107 | 113 | Query |
108 | 114 | QueryParser::parse_query(const string &query_string, unsigned flags, |
109 | 115 | const string &default_prefix) |
diff --git a/xapian-core/queryparser/queryparser.lemony b/xapian-core/queryparser/queryparser.lemony
index b6dc261..328f63f 100644
a
|
b
|
class State {
|
226 | 226 | Database get_database() const { |
227 | 227 | return qpi->db; |
228 | 228 | } |
| 229 | |
| 230 | Xapian::termcount get_max_wildcard_expansion() { |
| 231 | return qpi->max_wildcard_expansion; |
| 232 | } |
229 | 233 | }; |
230 | 234 | |
231 | 235 | string |
… |
… |
Term::as_wildcarded_query(State * state_) const
|
335 | 339 | Database db = state_->get_database(); |
336 | 340 | vector<Query> subqs; |
337 | 341 | list<string>::const_iterator piter; |
| 342 | long expansion_count = 0; |
| 343 | Xapian::termcount max = state_->get_max_wildcard_expansion(); |
338 | 344 | for (piter = prefixes.begin(); piter != prefixes.end(); ++piter) { |
339 | 345 | string root = *piter; |
340 | 346 | root += name; |
… |
… |
Term::as_wildcarded_query(State * state_) const
|
342 | 348 | while (t != db.allterms_end(root)) { |
343 | 349 | subqs.push_back(Query(*t, 1, pos)); |
344 | 350 | ++t; |
| 351 | if (max != 0 && ++expansion_count > max) { |
| 352 | throw Xapian::QueryParserError("Wildcard "+unstemmed+"* expands too much"); |
| 353 | } |
345 | 354 | } |
346 | 355 | } |
347 | 356 | delete this; |
diff --git a/xapian-core/queryparser/queryparser_internal.h b/xapian-core/queryparser/queryparser_internal.h
index 88cbb8f..439f583 100644
a
|
b
|
class QueryParser::Internal : public Xapian::Internal::RefCntBase {
|
74 | 74 | |
75 | 75 | string corrected_query; |
76 | 76 | |
| 77 | Xapian::termcount max_wildcard_expansion; |
| 78 | |
77 | 79 | void add_prefix(const string &field, const string &prefix, bool filter); |
78 | 80 | |
79 | 81 | std::string parse_term(Utf8Iterator &it, const Utf8Iterator &end, |
… |
… |
class QueryParser::Internal : public Xapian::Internal::RefCntBase {
|
81 | 83 | |
82 | 84 | public: |
83 | 85 | Internal() : stem_action(STEM_NONE), stopper(NULL), |
84 | | default_op(Query::OP_OR), errmsg(NULL) { } |
| 86 | default_op(Query::OP_OR), errmsg(NULL) { max_wildcard_expansion=0; } |
85 | 87 | Query parse_query(const string & query_string, unsigned int flags, const string & default_prefix); |
86 | 88 | }; |
87 | 89 | |