LCOV - code coverage report
Current view: top level - weight - weightinternal.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 4ba52dacf4fb Lines: 35 65 53.8 %
Date: 2019-05-20 14:58:19 Functions: 2 4 50.0 %
Branches: 33 116 28.4 %

           Branch data     Line data    Source code
       1                 :            : /** @file weightinternal.cc
       2                 :            :  * @brief Xapian::Weight::Internal class, holding database and term statistics.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007 Lemur Consulting Ltd
       5                 :            :  * Copyright (C) 2009,2010,2011,2012,2013,2014,2015,2017 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 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "weightinternal.h"
      25                 :            : 
      26                 :            : #include "xapian/enquire.h"
      27                 :            : 
      28                 :            : #include "omassert.h"
      29                 :            : #include "api/rsetinternal.h"
      30                 :            : #include "str.h"
      31                 :            : #include "api/termlist.h"
      32                 :            : 
      33                 :            : #include <memory>
      34                 :            : #include <set>
      35                 :            : 
      36                 :            : using namespace std;
      37                 :            : 
      38                 :            : string
      39                 :          0 : TermFreqs::get_description() const {
      40         [ #  # ]:          0 :     string desc("TermFreqs(termfreq=");
      41 [ #  # ][ #  # ]:          0 :     desc += str(termfreq);
      42         [ #  # ]:          0 :     desc += ", reltermfreq=";
      43 [ #  # ][ #  # ]:          0 :     desc += str(reltermfreq);
      44         [ #  # ]:          0 :     desc += ", collfreq=";
      45 [ #  # ][ #  # ]:          0 :     desc += str(collfreq);
      46         [ #  # ]:          0 :     desc += ", max_part=";
      47 [ #  # ][ #  # ]:          0 :     desc += str(max_part);
      48         [ #  # ]:          0 :     desc += ")";
      49                 :          0 :     return desc;
      50                 :            : }
      51                 :            : 
      52                 :            : namespace Xapian {
      53                 :            : 
      54                 :            : Weight::Internal &
      55                 :      10414 : Weight::Internal::operator+=(const Weight::Internal & inc)
      56                 :            : {
      57                 :            : #ifdef XAPIAN_ASSERTIONS
      58                 :            :     Assert(!finalised);
      59                 :            :     subdbs += inc.subdbs;
      60                 :            : #endif
      61                 :      10414 :     total_length += inc.total_length;
      62                 :      10414 :     collection_size += inc.collection_size;
      63                 :      10414 :     rset_size += inc.rset_size;
      64                 :      10414 :     total_term_count += inc.total_term_count;
      65                 :            : 
      66                 :            :     // Add termfreqs and reltermfreqs
      67                 :      10414 :     map<string, TermFreqs>::const_iterator i;
      68         [ +  + ]:      17794 :     for (i = inc.termfreqs.begin(); i != inc.termfreqs.end(); ++i) {
      69         [ +  - ]:       7380 :         termfreqs[i->first] += i->second;
      70                 :            :     }
      71                 :      10414 :     return *this;
      72                 :            : }
      73                 :            : 
      74                 :            : void
      75                 :     178265 : Weight::Internal::accumulate_stats(const Xapian::Database::Internal &subdb,
      76                 :            :                                    const Xapian::RSet &rset)
      77                 :            : {
      78                 :            : #ifdef XAPIAN_ASSERTIONS
      79                 :            :     Assert(!finalised);
      80                 :            :     ++subdbs;
      81                 :            : #endif
      82         [ +  - ]:     178265 :     total_length += subdb.get_total_length();
      83         [ +  - ]:     178265 :     collection_size += subdb.get_doccount();
      84         [ +  - ]:     178265 :     rset_size += rset.size();
      85                 :            : 
      86 [ +  - ][ +  - ]:     178265 :     total_term_count += subdb.get_doccount() * subdb.get_total_length();
      87                 :     178265 :     Xapian::TermIterator t;
      88 [ +  - ][ +  - ]:     486578 :     for (t = query.get_unique_terms_begin(); t != Xapian::TermIterator(); ++t) {
         [ +  - ][ +  + ]
      89         [ +  - ]:     308314 :         const string & term = *t;
      90                 :            : 
      91                 :            :         Xapian::doccount sub_tf;
      92                 :            :         Xapian::termcount sub_cf;
      93         [ +  + ]:     308314 :         subdb.get_freqs(term, &sub_tf, &sub_cf);
      94         [ +  - ]:     308313 :         TermFreqs & tf = termfreqs[term];
      95                 :     308313 :         tf.termfreq += sub_tf;
      96                 :     308313 :         tf.collfreq += sub_cf;
      97                 :     308314 :     }
      98                 :            : 
      99         [ +  + ]:     178264 :     if (!rset.internal.get())
     100                 :     356467 :         return;
     101                 :            : 
     102 [ +  + ][ +  + ]:     178325 :     for (Xapian::docid did : rset.internal->docs) {
     103                 :            :         Assert(did);
     104                 :            :         // The query is likely to contain far fewer terms than the documents,
     105                 :            :         // and we can skip the document's termlist, so look for each query term
     106                 :            :         // in the document.
     107         [ +  - ]:         61 :         unique_ptr<TermList> tl(subdb.open_term_list(did));
     108                 :         61 :         map<string, TermFreqs>::iterator i;
     109         [ +  + ]:        155 :         for (i = termfreqs.begin(); i != termfreqs.end(); ++i) {
     110                 :        110 :             const string & term = i->first;
     111         [ +  - ]:        110 :             TermList * ret = tl->skip_to(term);
     112                 :            :             Assert(ret == NULL);
     113                 :            :             (void)ret;
     114 [ +  - ][ +  + ]:        110 :             if (tl->at_end())
     115                 :         16 :                 break;
     116 [ +  - ][ +  + ]:         94 :             if (term == tl->get_termname())
     117                 :         68 :                 ++i->second.reltermfreq;
     118                 :            :         }
     119                 :     178326 :     }
     120                 :            : }
     121                 :            : 
     122                 :            : string
     123                 :          0 : Weight::Internal::get_description() const
     124                 :            : {
     125         [ #  # ]:          0 :     string desc = "Weight::Internal(totlen=";
     126 [ #  # ][ #  # ]:          0 :     desc += str(total_length);
     127         [ #  # ]:          0 :     desc += ", collection_size=";
     128 [ #  # ][ #  # ]:          0 :     desc += str(collection_size);
     129         [ #  # ]:          0 :     desc += ", rset_size=";
     130 [ #  # ][ #  # ]:          0 :     desc += str(rset_size);
     131         [ #  # ]:          0 :     desc += ", total_term_count=";
     132 [ #  # ][ #  # ]:          0 :     desc += str(total_term_count);
     133                 :            : #ifdef XAPIAN_ASSERTIONS
     134                 :            :     desc += ", subdbs=";
     135                 :            :     desc += str(subdbs);
     136                 :            :     desc += ", finalised=";
     137                 :            :     desc += str(finalised);
     138                 :            : #endif
     139         [ #  # ]:          0 :     desc += ", termfreqs={";
     140                 :          0 :     map<string, TermFreqs>::const_iterator i;
     141         [ #  # ]:          0 :     for (i = termfreqs.begin(); i != termfreqs.end(); ++i) {
     142         [ #  # ]:          0 :         if (i != termfreqs.begin())
     143         [ #  # ]:          0 :             desc += ", ";
     144         [ #  # ]:          0 :         desc += i->first;
     145         [ #  # ]:          0 :         desc += " => ";
     146 [ #  # ][ #  # ]:          0 :         desc += i->second.get_description();
     147                 :            :     }
     148         [ #  # ]:          0 :     desc += "})";
     149                 :          0 :     return desc;
     150                 :            : }
     151                 :            : 
     152                 :            : }

Generated by: LCOV version 1.11