"Fossies" - the Fresh Open Source Software Archive

Member "xapian-core-1.4.14/matcher/andmaybepostlist.cc" (23 Nov 2019, 6778 Bytes) of package /linux/www/xapian-core-1.4.14.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "andmaybepostlist.cc" see the Fossies "Dox" file reference documentation.

    1 /* andmaybepostlist.cc: Merged postlist; items from one list, weights from both
    2  *
    3  * Copyright 1999,2000,2001 BrightStation PLC
    4  * Copyright 2002 Ananova Ltd
    5  * Copyright 2003,2004,2005,2008,2009,2011,2017 Olly Betts
    6  * Copyright 2009 Lemur Consulting Ltd
    7  *
    8  * This program is free software; you can redistribute it and/or
    9  * modify it under the terms of the GNU General Public License as
   10  * published by the Free Software Foundation; either version 2 of the
   11  * License, or (at your option) any later version.
   12  *
   13  * This program is distributed in the hope that it will be useful,
   14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  * GNU General Public License for more details.
   17  *
   18  * You should have received a copy of the GNU General Public License
   19  * along with this program; if not, write to the Free Software
   20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
   21  * USA
   22  */
   23 
   24 #include <config.h>
   25 #include "andmaybepostlist.h"
   26 
   27 #include "debuglog.h"
   28 #include "multiandpostlist.h"
   29 #include "omassert.h"
   30 
   31 PostList *
   32 AndMaybePostList::process_next_or_skip_to(double w_min, PostList *ret)
   33 {
   34     LOGCALL(MATCH, PostList *, "AndMaybePostList::process_next_or_skip_to", w_min | ret);
   35     handle_prune(l, ret);
   36     if (l->at_end()) {
   37     // once l is over, so is the AND MAYBE
   38     lhead = 0;
   39     RETURN(NULL);
   40     }
   41 
   42     lhead = l->get_docid();
   43     if (lhead <= rhead) RETURN(NULL);
   44 
   45     bool valid;
   46     check_handling_prune(r, lhead, w_min - lmax, matcher, valid);
   47     if (r->at_end()) {
   48     PostList *tmp = l;
   49     l = NULL;
   50     RETURN(tmp);
   51     }
   52     if (valid) {
   53     rhead = r->get_docid();
   54     } else {
   55     rhead = 0;
   56     }
   57     RETURN(NULL);
   58 }
   59 
   60 PostList *
   61 AndMaybePostList::sync_rhs(double w_min)
   62 {
   63     LOGCALL(MATCH, PostList *, "AndMaybePostList::sync_rhs", w_min);
   64     bool valid;
   65     check_handling_prune(r, lhead, w_min - lmax, matcher, valid);
   66     if (r->at_end()) {
   67     PostList *tmp = l;
   68     l = NULL;
   69     RETURN(tmp);
   70     }
   71     if (valid) {
   72     rhead = r->get_docid();
   73     } else {
   74     rhead = 0;
   75     }
   76     RETURN(NULL);
   77 }
   78 
   79 PostList *
   80 AndMaybePostList::next(double w_min)
   81 {
   82     LOGCALL(MATCH, PostList *, "AndMaybePostList::next", w_min);
   83     if (w_min > lmax) {
   84     // we can replace the AND MAYBE with an AND
   85     PostList *ret;
   86     LOGLINE(MATCH, "AND MAYBE -> AND");
   87     ret = new MultiAndPostList(l, r, lmax, rmax, matcher, dbsize);
   88     l = r = NULL;
   89     skip_to_handling_prune(ret, std::max(lhead, rhead) + 1, w_min, matcher);
   90     RETURN(ret);
   91     }
   92     RETURN(process_next_or_skip_to(w_min, l->next(w_min - rmax)));
   93 }
   94 
   95 PostList *
   96 AndMaybePostList::skip_to(Xapian::docid did, double w_min)
   97 {
   98     LOGCALL(MATCH, PostList *, "AndMaybePostList::skip_to", did | w_min);
   99     if (w_min > lmax) {
  100     // we can replace the AND MAYBE with an AND
  101     PostList *ret;
  102     LOGLINE(MATCH, "AND MAYBE -> AND (in skip_to)");
  103     ret = new MultiAndPostList(l, r, lmax, rmax, matcher, dbsize);
  104     did = std::max(did, std::max(lhead, rhead));
  105     l = r = NULL;
  106     skip_to_handling_prune(ret, did, w_min, matcher);
  107     RETURN(ret);
  108     }
  109 
  110     // exit if we're already past the skip point (or at it)
  111     if (did <= lhead) RETURN(NULL);
  112 
  113     RETURN(process_next_or_skip_to(w_min, l->skip_to(did, w_min - rmax)));
  114 }
  115 
  116 Xapian::doccount
  117 AndMaybePostList::get_termfreq_max() const
  118 {
  119     LOGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_max", NO_ARGS);
  120     // Termfreq is exactly that of left hand branch.
  121     RETURN(l->get_termfreq_max());
  122 }
  123 
  124 Xapian::doccount
  125 AndMaybePostList::get_termfreq_min() const
  126 {
  127     LOGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_min", NO_ARGS);
  128     // Termfreq is exactly that of left hand branch.
  129     RETURN(l->get_termfreq_min());
  130 }
  131 
  132 Xapian::doccount
  133 AndMaybePostList::get_termfreq_est() const
  134 {
  135     LOGCALL(MATCH, Xapian::doccount, "AndMaybePostList::get_termfreq_est", NO_ARGS);
  136     // Termfreq is exactly that of left hand branch.
  137     RETURN(l->get_termfreq_est());
  138 }
  139 
  140 TermFreqs
  141 AndMaybePostList::get_termfreq_est_using_stats(
  142     const Xapian::Weight::Internal & stats) const
  143 {
  144     LOGCALL(MATCH, TermFreqs, "AndMaybePostList::get_termfreq_est_using_stats", stats);
  145     // Termfreq is exactly that of left hand branch.
  146     RETURN(l->get_termfreq_est_using_stats(stats));
  147 }
  148 
  149 Xapian::docid
  150 AndMaybePostList::get_docid() const
  151 {
  152     LOGCALL(MATCH, Xapian::docid, "AndMaybePostList::get_docid", NO_ARGS);
  153     Assert(lhead != 0); // check we've started
  154     RETURN(lhead);
  155 }
  156 
  157 // only called if we are doing a probabilistic AND MAYBE
  158 double
  159 AndMaybePostList::get_weight() const
  160 {
  161     LOGCALL(MATCH, double, "AndMaybePostList::get_weight", NO_ARGS);
  162     Assert(lhead != 0); // check we've started
  163     if (lhead == rhead) RETURN(l->get_weight() + r->get_weight());
  164     RETURN(l->get_weight());
  165 }
  166 
  167 // only called if we are doing a probabilistic operation
  168 double
  169 AndMaybePostList::get_maxweight() const
  170 {
  171     LOGCALL(MATCH, double, "AndMaybePostList::get_maxweight", NO_ARGS);
  172     RETURN(lmax + rmax);
  173 }
  174 
  175 double
  176 AndMaybePostList::recalc_maxweight()
  177 {
  178     LOGCALL(MATCH, double, "AndMaybePostList::recalc_maxweight", NO_ARGS);
  179     lmax = l->recalc_maxweight();
  180     rmax = r->recalc_maxweight();
  181     RETURN(AndMaybePostList::get_maxweight());
  182 }
  183 
  184 bool
  185 AndMaybePostList::at_end() const
  186 {
  187     LOGCALL(MATCH, bool, "AndMaybePostList::at_end", NO_ARGS);
  188     RETURN(lhead == 0);
  189 }
  190 
  191 std::string
  192 AndMaybePostList::get_description() const
  193 {
  194     return "(" + l->get_description() + " AndMaybe " + r->get_description() +
  195        ")";
  196 }
  197 
  198 Xapian::termcount
  199 AndMaybePostList::get_doclength() const
  200 {
  201     LOGCALL(MATCH, Xapian::termcount, "AndMaybePostList::get_doclength", NO_ARGS);
  202     Assert(lhead != 0); // check we've started
  203     if (lhead == rhead) AssertEq(l->get_doclength(), r->get_doclength());
  204     RETURN(l->get_doclength());
  205 }
  206 
  207 Xapian::termcount
  208 AndMaybePostList::get_unique_terms() const
  209 {
  210     LOGCALL(MATCH, Xapian::termcount, "AndMaybePostList::get_unique_terms", NO_ARGS);
  211     Assert(lhead != 0); // check we've started
  212     if (lhead == rhead) AssertEq(l->get_unique_terms(), r->get_unique_terms());
  213     RETURN(l->get_unique_terms());
  214 }
  215 
  216 Xapian::termcount
  217 AndMaybePostList::get_wdf() const
  218 {
  219     LOGCALL(MATCH, Xapian::termcount, "AndMaybePostList::get_wdf", NO_ARGS);
  220     if (lhead == rhead) RETURN(l->get_wdf() + r->get_wdf());
  221     RETURN(l->get_wdf());
  222 }
  223 
  224 Xapian::termcount
  225 AndMaybePostList::count_matching_subqs() const
  226 {
  227     LOGCALL(MATCH, Xapian::termcount, "AndMaybePostList::count_matching_subqs", NO_ARGS);
  228     if (lhead == rhead)
  229     RETURN(l->count_matching_subqs() + r->count_matching_subqs());
  230     RETURN(l->count_matching_subqs());
  231 }
  232 
  233 void
  234 AndMaybePostList::gather_position_lists(OrPositionList* orposlist)
  235 {
  236     l->gather_position_lists(orposlist);
  237     if (lhead == rhead) r->gather_position_lists(orposlist);
  238 }