Ticket #608: 608-lazy-wildcard.patch

File 608-lazy-wildcard.patch, 2.1 KB (added by Olly Betts, 9 years ago)

New implementation on top of the lazy wildcard support

  • xapian-core/api/queryinternal.cc

    diff --git a/xapian-core/api/queryinternal.cc b/xapian-core/api/queryinternal.cc
    index b5d44ff..20f9a2e 100644
    a b class OrContext : public Context {  
    166166    /// Select the best set_size postlists from the last out_of added.
    167167    void select_elite_set(size_t set_size, size_t out_of);
    168168
     169    /// Select the set_size postlists with the highest term frequency.
     170    void select_most_frequent(size_t set_size);
     171
    169172    PostList * postlist(QueryOptimiser* qopt);
    170173    PostList * postlist_max(QueryOptimiser* qopt);
    171174};
    OrContext::select_elite_set(size_t set_size, size_t out_of)  
    183186    pls.resize(pls.size() - out_of + set_size);
    184187}
    185188
     189void
     190OrContext::select_most_frequent(size_t set_size)
     191{
     192    vector<PostList*>::iterator begin = pls.begin();
     193    nth_element(begin, begin + set_size - 1, pls.end(),
     194                ComparePostListTermFreqAscending());
     195    for_each(begin + set_size, pls.end(), delete_ptr<PostList>());
     196    pls.resize(set_size);
     197}
     198
    186199PostList *
    187200OrContext::postlist(QueryOptimiser* qopt)
    188201{
    QueryWildcard::postlist(QueryOptimiser * qopt, double factor) const  
    854867    }
    855868    OrContext ctx(0);
    856869    AutoPtr<TermList> t(qopt->db.open_allterms(pattern));
     870#if 0
    857871    Xapian::termcount expansions_left = max_expansion;
    858872    // If there's no expansion limit, set expansions_left to the maximum
    859873    // value Xapian::termcount can hold.
    860874    if (expansions_left == 0)
    861875        --expansions_left;
     876#endif
    862877    while (true) {
    863878        t->next();
    864879        if (t->at_end())
    865880            break;
     881#if 0
    866882        if (expansions_left-- == 0) {
    867883            string msg("Wildcard ");
    868884            msg += pattern;
    QueryWildcard::postlist(QueryOptimiser * qopt, double factor) const  
    871887            msg += " terms";
    872888            throw Xapian::WildcardError(msg);
    873889        }
     890#endif
    874891        const string & term = t->get_termname();
    875892        ctx.add_postlist(qopt->open_lazy_post_list(term, 1, or_factor));
    876893    }
    877894
     895    if (max_expansion && ctx.size() > max_expansion)
     896        ctx.select_most_frequent(max_expansion);
     897
    878898    if (factor != 0.0) {
    879899        if (op != Query::OP_SYNONYM) {
    880900            qopt->set_total_subqs(qopt->get_total_subqs() + ctx.size());