Ticket #245: qp-allstop.patch
File qp-allstop.patch, 3.0 KB (added by , 17 years ago) |
---|
-
queryparser/queryparser.lemony
174 174 QueryParser::Internal * qpi; 175 175 176 176 public: 177 const Stopper * stopper; 177 178 Query query; 178 179 const char * error; 179 180 unsigned flags; 180 181 181 182 State(QueryParser::Internal * qpi_, unsigned flags_) 182 : qpi(qpi_), error(NULL), flags(flags_) { }183 : qpi(qpi_), stopper(qpi->stopper), error(NULL), flags(flags_) { } 183 184 184 185 string stem_term(const string &term) { 185 186 return qpi->stemmer(term); … … 220 221 Query::op default_op() const { return qpi->default_op; } 221 222 222 223 bool is_stopword(const Term *term) const { 223 return qpi->stopper && (*qpi->stopper)(term->name);224 return stopper && (*stopper)(term->name); 224 225 } 225 226 226 227 Database get_database() const { … … 547 548 bool value_ranges; 548 549 value_ranges = !valrangeprocs.empty() && (qs.find("..") != string::npos); 549 550 551 State state(this, flags); 552 553 reparse_without_stopwords: 550 554 termpos term_pos = 1; 551 555 Utf8Iterator it(qs), end; 552 556 553 State state(this, flags);554 555 557 // To successfully apply more than one spelling correction to a query 556 558 // string, we must keep track of the offset due to previous corrections. 557 559 int correction_offset = 0; … … 1029 1031 if (mode == IN_QUOTES || mode == IN_PREFIXED_QUOTES) 1030 1032 Parse(pParser, QUOTE, NULL, &state); 1031 1033 Parse(pParser, 0, NULL, &state); 1034 1035 if (!state.error && state.query.empty() && state.stopper && 1036 !stoplist.empty()) { 1037 // All terms were stopwords so reparse with stopwords disabled. 1038 stoplist.clear(); 1039 unstem.clear(); 1040 state.stopper = NULL; 1041 goto reparse_without_stopwords; 1042 } 1032 1043 ParseFree(pParser); 1033 1044 1034 1045 errmsg = state.error; … … 1447 1458 } 1448 1459 *E = Query(Query::OP_AND_NOT, *E, *P->hate); 1449 1460 } 1450 // FIXME what if E && E->empty() (all terms are stopwords)?1451 1461 delete P; 1452 1462 } 1453 1463 -
tests/queryparsertest.cc
1007 1007 // parse. 1008 1008 { "test AND the AND queryparser", "(test:(pos=1) AND the:(pos=2) AND queryparser:(pos=3))" }, 1009 1009 // 0.9.6 and earlier ignored a stopword even if it was the only term. 1010 // We don't ignore it in this case, which is probably better. But 1011 // an all-stopword query with multiple terms doesn't work, which 1012 // prevents 'to be or not to be' for being searchable unless made 1013 // into a phrase query. 1010 // More recent versions don't ever treat a single term as a stopword. 1014 1011 { "the", "the:(pos=1)" }, 1012 // 1.0.5 and earlier ignored an all-stopword query with multiple terms, 1013 // which prevents 'to be or not to be' for being searchable unless made 1014 // into a phrase query by the user. 1015 { "an the a", "(an:(pos=1) AND the:(pos=2) AND a:(pos=3))" }, 1016 // FIXME: this still doesn't work... 1017 { "the AND a an", "" }, 1015 1018 { NULL, NULL } 1016 1019 }; 1017 1020