LCOV - code coverage report
Current view: top level - weight - weight.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 4ba52dacf4fb Lines: 52 71 73.2 %
Date: 2019-05-20 14:58:19 Functions: 4 10 40.0 %
Branches: 23 56 41.1 %

           Branch data     Line data    Source code
       1                 :            : /** @file weight.cc
       2                 :            :  * @brief Xapian::Weight base class
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2014,2017 Olly Betts
       5                 :            :  * Copyright (C) 2009 Lemur Consulting Ltd
       6                 :            :  * Copyright (C) 2017 Vivek Pal
       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 USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : 
      25                 :            : #include "xapian/weight.h"
      26                 :            : 
      27                 :            : #include "weightinternal.h"
      28                 :            : 
      29                 :            : #include "omassert.h"
      30                 :            : #include "debuglog.h"
      31                 :            : 
      32                 :            : #include "xapian/error.h"
      33                 :            : 
      34                 :            : using namespace std;
      35                 :            : 
      36                 :            : namespace Xapian {
      37                 :            : 
      38                 :            : void
      39                 :     178026 : Weight::init_(const Internal & stats, Xapian::termcount query_length)
      40                 :            : {
      41                 :            :     LOGCALL_VOID(MATCH, "Weight::init_", stats | query_length);
      42                 :     178026 :     collection_size_ = stats.collection_size;
      43                 :     178026 :     rset_size_ = stats.rset_size;
      44         [ +  + ]:     178026 :     if (stats_needed & AVERAGE_LENGTH)
      45                 :     177396 :         average_length_ = stats.get_average_length();
      46         [ +  + ]:     178026 :     if (stats_needed & DOC_LENGTH_MAX)
      47                 :       1484 :         doclength_upper_bound_ = stats.db.get_doclength_upper_bound();
      48         [ +  + ]:     178026 :     if (stats_needed & DOC_LENGTH_MIN)
      49                 :     177356 :         doclength_lower_bound_ = stats.db.get_doclength_lower_bound();
      50                 :     178026 :     collectionfreq_ = 0;
      51                 :     178026 :     wdf_upper_bound_ = 0;
      52                 :     178026 :     termfreq_ = 0;
      53                 :     178026 :     reltermfreq_ = 0;
      54                 :     178026 :     query_length_ = query_length;
      55                 :     178026 :     wqf_ = 1;
      56                 :     178026 :     init(0.0);
      57                 :     178026 : }
      58                 :            : 
      59                 :            : void
      60                 :     310719 : Weight::init_(const Internal & stats, Xapian::termcount query_length,
      61                 :            :               const string & term, Xapian::termcount wqf, double factor)
      62                 :            : {
      63                 :            :     LOGCALL_VOID(MATCH, "Weight::init_", stats | query_length | term | wqf | factor);
      64                 :     310719 :     collection_size_ = stats.collection_size;
      65                 :     310719 :     rset_size_ = stats.rset_size;
      66         [ +  + ]:     310719 :     if (stats_needed & AVERAGE_LENGTH)
      67                 :     309537 :         average_length_ = stats.get_average_length();
      68         [ +  + ]:     310719 :     if (stats_needed & DOC_LENGTH_MAX)
      69                 :       1594 :         doclength_upper_bound_ = stats.db.get_doclength_upper_bound();
      70         [ +  + ]:     310719 :     if (stats_needed & DOC_LENGTH_MIN)
      71                 :     309513 :         doclength_lower_bound_ = stats.db.get_doclength_lower_bound();
      72         [ +  + ]:     310719 :     if (stats_needed & WDF_MAX)
      73                 :     309689 :         wdf_upper_bound_ = stats.db.get_wdf_upper_bound(term);
      74         [ +  + ]:     310719 :     if (stats_needed & (TERMFREQ | RELTERMFREQ | COLLECTION_FREQ)) {
      75                 :            :         bool ok = stats.get_stats(term,
      76                 :     309657 :                                   termfreq_, reltermfreq_, collectionfreq_);
      77                 :            :         (void)ok;
      78                 :            :         Assert(ok);
      79                 :            :     }
      80                 :     310719 :     query_length_ = query_length;
      81                 :     310719 :     wqf_ = wqf;
      82                 :     310719 :     init(factor);
      83                 :     310719 : }
      84                 :            : 
      85                 :            : void
      86                 :        801 : Weight::init_(const Internal & stats, Xapian::termcount query_length,
      87                 :            :               double factor, Xapian::doccount termfreq,
      88                 :            :               Xapian::doccount reltermfreq, Xapian::termcount collection_freq)
      89                 :            : {
      90                 :            :     LOGCALL_VOID(MATCH, "Weight::init_", stats | query_length | factor | termfreq | reltermfreq | collection_freq);
      91                 :            :     // Synonym case.
      92                 :        801 :     collection_size_ = stats.collection_size;
      93                 :        801 :     rset_size_ = stats.rset_size;
      94         [ +  + ]:        801 :     if (stats_needed & AVERAGE_LENGTH)
      95                 :        761 :         average_length_ = stats.get_average_length();
      96         [ +  + ]:        801 :     if (stats_needed & (DOC_LENGTH_MAX | WDF_MAX)) {
      97                 :        761 :         doclength_upper_bound_ = stats.db.get_doclength_upper_bound();
      98                 :            :         // The doclength is an upper bound on the wdf.  This is obviously true
      99                 :            :         // for normal terms, but SynonymPostList ensures that it is also true
     100                 :            :         // for synonym terms by clamping the wdf values returned to the
     101                 :            :         // doclength.
     102                 :            :         //
     103                 :            :         // (This clamping is only actually necessary in cases where a constituent
     104                 :            :         // term of the synonym is repeated.)
     105                 :        761 :         wdf_upper_bound_ = doclength_upper_bound_;
     106                 :            :     }
     107         [ +  + ]:        801 :     if (stats_needed & DOC_LENGTH_MIN)
     108                 :        761 :         doclength_lower_bound_ = stats.db.get_doclength_lower_bound();
     109                 :            : 
     110                 :        801 :     termfreq_ = termfreq;
     111                 :        801 :     reltermfreq_ = reltermfreq;
     112                 :        801 :     query_length_ = query_length;
     113                 :        801 :     collectionfreq_ = collection_freq;
     114                 :        801 :     wqf_ = 1;
     115                 :        801 :     init(factor);
     116                 :        801 : }
     117                 :            : 
     118         [ -  + ]:    1075200 : Weight::~Weight() { }
     119                 :            : 
     120                 :            : string
     121                 :          0 : Weight::name() const
     122                 :            : {
     123                 :          0 :     return string();
     124                 :            : }
     125                 :            : 
     126                 :            : string
     127                 :          0 : Weight::short_name() const
     128                 :            : {
     129                 :          0 :     return string();
     130                 :            : }
     131                 :            : 
     132                 :            : string
     133                 :          0 : Weight::serialise() const
     134                 :            : {
     135 [ #  # ][ #  # ]:          0 :     throw Xapian::UnimplementedError("serialise() not supported for this Xapian::Weight subclass");
                 [ #  # ]
     136                 :            : }
     137                 :            : 
     138                 :            : Weight *
     139                 :          0 : Weight::unserialise(const string &) const
     140                 :            : {
     141 [ #  # ][ #  # ]:          0 :     throw Xapian::UnimplementedError("unserialise() not supported for this Xapian::Weight subclass");
                 [ #  # ]
     142                 :            : }
     143                 :            : 
     144                 :            : const Weight *
     145                 :          0 : Weight::create(const string & s, const Registry & reg)
     146                 :            : {
     147                 :          0 :     const char *p = s.c_str();
     148         [ #  # ]:          0 :     std::string scheme;
     149                 :            : 
     150         [ #  # ]:          0 :     while (*p != ' ') {
     151         [ #  # ]:          0 :         if (*p == '\0') break;
     152         [ #  # ]:          0 :         scheme += *p;
     153                 :          0 :         p++;
     154                 :            :     }
     155                 :            : 
     156         [ #  # ]:          0 :     if (*p == ' ') p++;
     157 [ #  # ][ #  # ]:          0 :     return reg.get_weighting_scheme(scheme)->create_from_parameters(p);
     158                 :            : }
     159                 :            : 
     160                 :            : Weight *
     161                 :          0 : Weight::create_from_parameters(const char *) const
     162                 :            : {
     163 [ #  # ][ #  # ]:          0 :     throw Xapian::UnimplementedError("create_from_parameters() not supported for this Xapian::Weight subclass");
                 [ #  # ]
     164                 :            : }
     165                 :            : 
     166                 :            : }

Generated by: LCOV version 1.11