diff -ubB v1/queryparser.lemony v2/queryparser.lemony
|
v1
|
v2
|
|
| 412 | 412 | return q; |
| 413 | 413 | } |
| 414 | 414 | |
| | 415 | class TermF |
| | 416 | { |
| | 417 | public: |
| | 418 | string term; |
| | 419 | Xapian::termcount freq; |
| | 420 | |
| | 421 | TermF(string t, Xapian::termcount f) { |
| | 422 | term = t; |
| | 423 | freq = f; |
| | 424 | } |
| | 425 | }; |
| | 426 | |
| | 427 | struct CompareFreq { |
| | 428 | bool operator()(const TermF a, const TermF b) { |
| | 429 | return a.freq > b.freq; |
| | 430 | } |
| | 431 | }; |
| | 432 | |
| 415 | 433 | Query * |
| 416 | 434 | Term::as_partial_query(State * state_) const |
| 417 | 435 | { |
| … |
… |
|
| 419 | 437 | vector<Query> subqs_partial; // A synonym of all the partial terms. |
| 420 | 438 | vector<Query> subqs_full; // A synonym of all the full terms. |
| 421 | 439 | |
| | 440 | unsigned int maxK = state_->get_max_wildcard_expansion(); |
| | 441 | if(maxK == 0) maxK = 100; |
| | 442 | unsigned int K = 0; |
| | 443 | Xapian::termcount min_freq = 1000000; |
| | 444 | Xapian::termcount freq = 0; |
| | 445 | |
| 422 | 446 | const list<string> & prefixes = prefix_info->prefixes; |
| 423 | 447 | list<string>::const_iterator piter; |
| | 448 | |
| 424 | 449 | for (piter = prefixes.begin(); piter != prefixes.end(); ++piter) { |
| 425 | 450 | string root = *piter; |
| 426 | 451 | root += name; |
| … |
… |
|
| 425 | 450 | string root = *piter; |
| 426 | 451 | root += name; |
| 427 | 452 | TermIterator t = db.allterms_begin(root); |
| | 453 | vector<TermF> terms; |
| | 454 | |
| 428 | 455 | while (t != db.allterms_end(root)) { |
| 429 | | subqs_partial.push_back(Query(*t, 1, pos)); |
| | 456 | freq = t.get_termfreq(); |
| | 457 | if(K < maxK) { |
| | 458 | if(min_freq > freq) |
| | 459 | min_freq = freq; |
| | 460 | |
| | 461 | terms.push_back(TermF(*t, freq)); |
| | 462 | } |
| | 463 | else { |
| | 464 | if(K == maxK) { |
| | 465 | make_heap( terms.begin(), terms.end(), CompareFreq() ); |
| | 466 | } |
| | 467 | |
| | 468 | if(min_freq < freq) { |
| | 469 | pop_heap( terms.begin(),terms.end(), CompareFreq() ); terms.pop_back(); |
| | 470 | terms.push_back( TermF(*t, freq) ); push_heap( terms.begin(), terms.end(), CompareFreq() ); |
| | 471 | min_freq = terms.front().freq; |
| | 472 | } |
| | 473 | } |
| | 474 | |
| | 475 | ++K; |
| 430 | 476 | ++t; |
| 431 | 477 | } |
| | 478 | |
| | 479 | for(unsigned int j = 0; j < terms.size(); j++) |
| | 480 | { |
| | 481 | subqs_partial.push_back(Query(terms[j].term, 1, pos)); |
| | 482 | } |
| | 483 | |
| 432 | 484 | // Add the term, as it would normally be handled, as an alternative. |
| 433 | 485 | subqs_full.push_back(Query(make_term(*piter), 1, pos)); |
| 434 | 486 | } |