LCOV - code coverage report
Current view: top level - weight - weight.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 49 58 84.5 %
Date: 2011-08-21 Functions: 4 9 44.4 %
Branches: 21 32 65.6 %

           Branch data     Line data    Source code
       1                 :            : /** @file weight.cc
       2                 :            :  * @brief Xapian::Weight base class
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009 Olly Betts
       5                 :            :  * Copyright (C) 2009 Lemur Consulting Ltd
       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 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "xapian/weight.h"
      25                 :            : 
      26                 :            : #include "weightinternal.h"
      27                 :            : 
      28                 :            : #include "debuglog.h"
      29                 :            : 
      30                 :            : #include "xapian/error.h"
      31                 :            : 
      32                 :            : using namespace std;
      33                 :            : 
      34                 :            : namespace Xapian {
      35                 :            : 
      36                 :            : void
      37                 :     246352 : Weight::init_(const Internal & stats, Xapian::termcount query_length)
      38                 :            : {
      39                 :            :     LOGCALL_VOID(MATCH, "Weight::init_", stats | query_length);
      40                 :     246352 :     collection_size_ = stats.collection_size;
      41                 :     246352 :     rset_size_ = stats.rset_size;
      42         [ +  + ]:     246352 :     if (stats_needed & AVERAGE_LENGTH)
      43                 :     245536 :         average_length_ = stats.get_average_length();
      44         [ -  + ]:     246352 :     if (stats_needed & DOC_LENGTH_MAX)
      45                 :          0 :         doclength_upper_bound_ = stats.db.get_doclength_upper_bound();
      46         [ +  + ]:     246352 :     if (stats_needed & DOC_LENGTH_MIN)
      47                 :     245568 :         doclength_lower_bound_ = stats.db.get_doclength_lower_bound();
      48                 :     246352 :     wdf_upper_bound_ = 0;
      49                 :     246352 :     termfreq_ = 0;
      50                 :     246352 :     reltermfreq_ = 0;
      51                 :     246352 :     query_length_ = query_length;
      52                 :     246352 :     wqf_ = 1;
      53                 :     246352 : }
      54                 :            : 
      55                 :            : void
      56                 :     473840 : Weight::init_(const Internal & stats, Xapian::termcount query_length,
      57                 :            :               const string & term, Xapian::termcount wqf, double factor)
      58                 :            : {
      59                 :            :     LOGCALL_VOID(MATCH, "Weight::init_", stats | query_length | term | wqf | factor);
      60                 :     473840 :     collection_size_ = stats.collection_size;
      61                 :     473840 :     rset_size_ = stats.rset_size;
      62         [ +  + ]:     473840 :     if (stats_needed & AVERAGE_LENGTH)
      63                 :     471900 :         average_length_ = stats.get_average_length();
      64         [ -  + ]:     473840 :     if (stats_needed & DOC_LENGTH_MAX)
      65                 :          0 :         doclength_upper_bound_ = stats.db.get_doclength_upper_bound();
      66         [ +  + ]:     473840 :     if (stats_needed & DOC_LENGTH_MIN)
      67                 :     471932 :         doclength_lower_bound_ = stats.db.get_doclength_lower_bound();
      68         [ +  + ]:     473840 :     if (stats_needed & WDF_MAX)
      69                 :     471948 :         wdf_upper_bound_ = stats.db.get_wdf_upper_bound(term);
      70         [ +  + ]:     473840 :     if (stats_needed & TERMFREQ)
      71                 :     471948 :         termfreq_ = stats.get_termfreq(term);
      72         [ +  + ]:     473840 :     if (stats_needed & RELTERMFREQ)
      73                 :     471948 :         reltermfreq_ = stats.get_reltermfreq(term);
      74                 :     473840 :     query_length_ = query_length;
      75                 :     473840 :     wqf_ = wqf;
      76                 :     473840 :     init(factor);
      77                 :     473840 : }
      78                 :            : 
      79                 :            : void
      80                 :        592 : Weight::init_(const Internal & stats, Xapian::termcount query_length,
      81                 :            :               double factor, Xapian::doccount termfreq,
      82                 :            :               Xapian::doccount reltermfreq)
      83                 :            : {
      84                 :            :     LOGCALL_VOID(MATCH, "Weight::init_", stats | query_length | factor | termfreq | reltermfreq);
      85                 :            :     // Synonym case.
      86                 :        592 :     collection_size_ = stats.collection_size;
      87                 :        592 :     rset_size_ = stats.rset_size;
      88         [ +  - ]:        592 :     if (stats_needed & AVERAGE_LENGTH)
      89                 :        592 :         average_length_ = stats.get_average_length();
      90         [ -  + ]:        592 :     if (stats_needed & DOC_LENGTH_MAX)
      91                 :          0 :         doclength_upper_bound_ = stats.db.get_doclength_upper_bound();
      92         [ +  - ]:        592 :     if (stats_needed & DOC_LENGTH_MIN)
      93                 :        592 :         doclength_lower_bound_ = stats.db.get_doclength_lower_bound();
      94                 :            : 
      95                 :            :     // The doclength is an upper bound on the wdf.  This is obviously true for
      96                 :            :     // normal terms, but SynonymPostList ensures that it is also true for
      97                 :            :     // synonym terms by clamping the wdf values returned to the doclength.
      98                 :            :     //
      99                 :            :     // (This clamping is only actually necessary in cases where a constituent
     100                 :            :     // term of the synonym is repeated.)
     101         [ +  - ]:        592 :     if (stats_needed & WDF_MAX)
     102                 :        592 :         wdf_upper_bound_ = stats.db.get_doclength_upper_bound();
     103                 :            : 
     104                 :        592 :     termfreq_ = termfreq;
     105                 :        592 :     reltermfreq_ = reltermfreq;
     106                 :        592 :     query_length_ = query_length;
     107                 :        592 :     wqf_ = 1;
     108                 :        592 :     init(factor);
     109                 :        592 : }
     110                 :            : 
     111 [ #  # ][ #  # ]:     735837 : Weight::~Weight() { }
                 [ -  + ]
     112                 :            : 
     113                 :            : string
     114                 :          0 : Weight::name() const
     115                 :            : {
     116                 :          0 :     return string();
     117                 :            : }
     118                 :            : 
     119                 :            : string
     120                 :          0 : Weight::serialise() const
     121                 :            : {
     122                 :          0 :     throw Xapian::UnimplementedError("serialise() not supported for this Xapian::Weight subclass");
     123                 :            : }
     124                 :            : 
     125                 :            : Weight *
     126                 :          0 : Weight::unserialise(const string &) const
     127                 :            : {
     128                 :          0 :     throw Xapian::UnimplementedError("unserialise() not supported for this Xapian::Weight subclass");
     129                 :            : }
     130                 :            : 
     131                 :            : }

Generated by: LCOV version 1.8