LCOV - code coverage report
Current view: top level - matcher - synonympostlist.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 24 30 80.0 %
Date: 2019-06-30 05:20:33 Functions: 7 8 87.5 %
Branches: 10 26 38.5 %

           Branch data     Line data    Source code
       1                 :            : /** @file synonympostlist.cc
       2                 :            :  * @brief Combine subqueries, weighting as if they are synonyms
       3                 :            :  */
       4                 :            : /* Copyright 2007,2009 Lemur Consulting Ltd
       5                 :            :  * Copyright 2009,2011,2014,2016,2017,2018 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : 
      25                 :            : #include "synonympostlist.h"
      26                 :            : 
      27                 :            : #include "debuglog.h"
      28                 :            : #include "omassert.h"
      29                 :            : #include "postlisttree.h"
      30                 :            : 
      31                 :            : using namespace std;
      32                 :            : 
      33                 :       2448 : SynonymPostList::~SynonymPostList()
      34                 :            : {
      35         [ +  - ]:        816 :     delete wt;
      36         [ -  + ]:       1632 : }
      37                 :            : 
      38                 :            : void
      39                 :        816 : SynonymPostList::set_weight(const Xapian::Weight * wt_)
      40                 :            : {
      41         [ -  + ]:        816 :     delete wt;
      42                 :        816 :     wt = wt_;
      43                 :        816 :     want_wdf = wt->get_sumpart_needs_wdf_();
      44                 :        816 : }
      45                 :            : 
      46                 :            : PostList *
      47                 :       9490 : SynonymPostList::next(double w_min)
      48                 :            : {
      49                 :            :     LOGCALL(MATCH, PostList *, "SynonymPostList::next", w_min);
      50                 :            :     (void)w_min;
      51                 :       9490 :     RETURN(WrapperPostList::next(0.0));
      52                 :            : }
      53                 :            : 
      54                 :            : PostList *
      55                 :         29 : SynonymPostList::skip_to(Xapian::docid did, double w_min)
      56                 :            : {
      57                 :            :     LOGCALL(MATCH, PostList *, "SynonymPostList::skip_to", did | w_min);
      58                 :            :     (void)w_min;
      59                 :         29 :     RETURN(WrapperPostList::skip_to(did, 0.0));
      60                 :            : }
      61                 :            : 
      62                 :            : double
      63                 :       8546 : SynonymPostList::get_weight(Xapian::termcount doclen,
      64                 :            :                             Xapian::termcount unique_terms) const
      65                 :            : {
      66                 :            :     LOGCALL(MATCH, double, "SynonymPostList::get_weight", doclen | unique_terms);
      67                 :       8546 :     Xapian::termcount wdf = 0;
      68         [ +  - ]:       8546 :     if (want_wdf) {
      69                 :       8546 :         wdf = get_wdf();
      70                 :            :         // Use doclen_lower_bound as a cheap check to sometimes avoid the
      71                 :            :         // need to clamp.
      72 [ +  + ][ +  + ]:       8546 :         if (!wdf_disjoint && wdf > doclen_lower_bound) {
      73                 :            :             // If !wdf_disjoint, the subquery isn't known to be wdf-disjoint
      74                 :            :             // and so may return a wdf higher than the doclength.  In
      75                 :            :             // particular, this can currently occur if the query below
      76                 :            :             // OP_SYNONYM contains a term more than once; the wdf of each
      77                 :            :             // occurrence is added up.
      78                 :            :             //
      79                 :            :             // However, it's reasonable for weighting algorithms to optimise by
      80                 :            :             // assuming that get_wdf() will never return more than doclen, since
      81                 :            :             // doclen is the sum of the wdfs.
      82                 :            :             //
      83                 :            :             // Therefore, we simply clamp the wdf value to doclen to ensure
      84                 :            :             // that this is true.  Note that this requires doclen to be fetched
      85                 :            :             // even if the weight object doesn't want it.
      86         [ -  + ]:        649 :             if (doclen == 0) {
      87                 :            :                 Xapian::termcount dummy;
      88         [ #  # ]:          0 :                 pltree->get_doc_stats(doclen, dummy);
      89                 :            :             }
      90         [ -  + ]:       8546 :             if (wdf > doclen) wdf = doclen;
      91                 :            :         }
      92                 :            :     }
      93                 :       8546 :     RETURN(wt->get_sumpart(wdf, doclen, unique_terms));
      94                 :            : }
      95                 :            : 
      96                 :            : double
      97                 :        863 : SynonymPostList::recalc_maxweight()
      98                 :            : {
      99                 :            :     LOGCALL(MATCH, double, "SynonymPostList::recalc_maxweight", NO_ARGS);
     100                 :        863 :     RETURN(wt->get_maxpart());
     101                 :            : }
     102                 :            : 
     103                 :            : Xapian::termcount
     104                 :       1171 : SynonymPostList::count_matching_subqs() const
     105                 :            : {
     106                 :       1171 :     return 1;
     107                 :            : }
     108                 :            : 
     109                 :            : string
     110                 :          0 : SynonymPostList::get_description() const
     111                 :            : {
     112         [ #  # ]:          0 :     string desc = "SynonymPostList(";
     113 [ #  # ][ #  # ]:          0 :     desc += pl->get_description();
     114         [ #  # ]:          0 :     desc += ')';
     115                 :          0 :     return desc;
     116                 :            : }

Generated by: LCOV version 1.11