Ticket #350: Add-set_max_wildcard_expansion-method-to-the-queryparser-updated.patch
File Add-set_max_wildcard_expansion-method-to-the-queryparser-updated.patch, 4.0 KB (added by , 14 years ago) |
---|
-
docs/queryparser.html
117 117 to enable it, and tell the QueryParser which database to expand wildcards from 118 118 using the <code>QueryParser::set_database(<i>database</i>)</code> method. 119 119 120 <P>You can limit the number of terms a wildcard will expand to by 121 calling <code>Xapian::QueryParser::set_max_wildcard_expansion()</code>. If a 122 wildcard expands to more terms than that number, an exception will be 123 thrown. The exception may be thrown by the QueryParser, or later when 124 Enquire handles the query. The default is not to limit the expansion. 125 120 126 <H3>Partially entered query matching</H3> 121 127 122 128 <P> -
include/xapian/queryparser.h
446 446 */ 447 447 void set_database(const Database &db); 448 448 449 /** Specify the maximum expansion of a wildcard term. 450 * 451 * Note: you must also set FLAG_WILDCARD for wildcard expansion to happen. 452 * 453 * @param limit The maximum number of terms each wildcard in the query 454 * can expand to, or 0 for no limit. 455 */ 456 void set_max_wildcard_expansion(Xapian::termcount limit); 457 449 458 /** Parse a query. 450 459 * 451 460 * @param query_string A free-text query as entered by a user -
queryparser/queryparser.lemony
26 26 #include "queryparser_internal.h" 27 27 #include <xapian/error.h> 28 28 #include <xapian/unicode.h> 29 #include "str.h" 29 30 #include "stringutils.h" 30 31 31 32 // Include the list of token values lemon generates. … … 257 258 void stoplist_resize(size_t s) { 258 259 qpi->stoplist.resize(s); 259 260 } 261 262 Xapian::termcount get_max_wildcard_expansion() const { 263 return qpi->max_wildcard_expansion; 264 } 260 265 }; 261 266 262 267 string … … 370 375 371 376 const list<string> & prefixes = prefix_info->prefixes; 372 377 list<string>::const_iterator piter; 378 Xapian::termcount expansion_count = 0; 379 Xapian::termcount max = state_->get_max_wildcard_expansion(); 373 380 for (piter = prefixes.begin(); piter != prefixes.end(); ++piter) { 374 381 string root = *piter; 375 382 root += name; 376 383 TermIterator t = db.allterms_begin(root); 377 384 while (t != db.allterms_end(root)) { 385 if (max != 0 && ++expansion_count > max) { 386 string msg("Wilcard "); 387 msg += unstemmed; 388 msg += "* expands to more than "; 389 msg += str(max); 390 msg += " terms"; 391 throw Xapian::QueryParserError(msg); 392 } 378 393 subqs.push_back(Query(*t, 1, pos)); 379 394 ++t; 380 395 } -
queryparser/queryparser_internal.h
76 76 77 77 string corrected_query; 78 78 79 Xapian::termcount max_wildcard_expansion; 80 79 81 void add_prefix(const string &field, const string &prefix, 80 82 filter_type type); 81 83 … … 84 86 85 87 public: 86 88 Internal() : stem_action(STEM_NONE), stopper(NULL), 87 default_op(Query::OP_OR), errmsg(NULL) { }89 default_op(Query::OP_OR), errmsg(NULL), max_wildcard_expansion(0) { } 88 90 Query parse_query(const string & query_string, unsigned int flags, const string & default_prefix); 89 91 }; 90 92 -
queryparser/queryparser.cc
103 103 internal->db = db; 104 104 } 105 105 106 void 107 QueryParser::set_max_wildcard_expansion(Xapian::termcount max) 108 { 109 internal->max_wildcard_expansion = max; 110 } 111 106 112 Query 107 113 QueryParser::parse_query(const string &query_string, unsigned flags, 108 114 const string &default_prefix)