LCOV - code coverage report
Current view: top level - matcher - maxpostlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 15 17 88.2 %
Date: 2019-06-30 05:20:33 Functions: 2 3 66.7 %
Branches: 7 10 70.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file maxpostlist.h
       2                 :            :  * @brief N-way OR postlist with wt=max(wt_i)
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2009,2010,2011,2012,2013,2017,2018 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                 :            : #ifndef XAPIAN_INCLUDED_MAXPOSTLIST_H
      23                 :            : #define XAPIAN_INCLUDED_MAXPOSTLIST_H
      24                 :            : 
      25                 :            : #include "api/postlist.h"
      26                 :            : #include "postlisttree.h"
      27                 :            : 
      28                 :            : /// N-way OR postlist with wt=max(wt_i).
      29                 :            : class MaxPostList : public PostList {
      30                 :            :     /// Don't allow assignment.
      31                 :            :     void operator=(const MaxPostList &);
      32                 :            : 
      33                 :            :     /// Don't allow copying.
      34                 :            :     MaxPostList(const MaxPostList &);
      35                 :            : 
      36                 :            :     /// The current docid, or zero if we haven't started or are at_end.
      37                 :            :     Xapian::docid did;
      38                 :            : 
      39                 :            :     /// The number of sub-postlists.
      40                 :            :     size_t n_kids;
      41                 :            : 
      42                 :            :     /// Array of pointers to sub-postlists.
      43                 :            :     PostList ** plist;
      44                 :            : 
      45                 :            :     /// The number of documents in the database.
      46                 :            :     Xapian::doccount db_size;
      47                 :            : 
      48                 :            :     /// Pointer to the matcher object, so we can report pruning.
      49                 :            :     PostListTree *matcher;
      50                 :            : 
      51                 :            :     /// Erase a sub-postlist.
      52                 :          8 :     void erase_sublist(size_t i) {
      53         [ +  - ]:          8 :         delete plist[i];
      54                 :          8 :         --n_kids;
      55         [ +  + ]:          9 :         for (size_t j = i; j < n_kids; ++j) {
      56                 :          1 :             plist[j] = plist[j + 1];
      57                 :            :         }
      58                 :          8 :         matcher->force_recalc();
      59                 :          8 :     }
      60                 :            : 
      61                 :            :   public:
      62                 :            :     /** Construct from 2 random-access iterators to a container of PostList*,
      63                 :            :      *  a pointer to the matcher, and the document collection size.
      64                 :            :      */
      65                 :            :     template<class RandomItor>
      66                 :          8 :     MaxPostList(RandomItor pl_begin, RandomItor pl_end,
      67                 :            :                 PostListTree * matcher_, Xapian::doccount db_size_)
      68                 :          8 :         : did(0), n_kids(pl_end - pl_begin), plist(NULL),
      69                 :          8 :           db_size(db_size_), matcher(matcher_)
      70                 :            :     {
      71 [ +  - ][ +  - ]:          8 :         plist = new PostList * [n_kids];
      72                 :          8 :         auto it = plist;
      73         [ +  + ]:         24 :         while (pl_begin != pl_end) {
      74                 :         16 :             *it++ = (*pl_begin++).pl;
      75                 :            :         }
      76                 :          8 :     }
      77                 :            : 
      78                 :            :     ~MaxPostList();
      79                 :            : 
      80                 :            :     Xapian::doccount get_termfreq_min() const;
      81                 :            : 
      82                 :            :     Xapian::doccount get_termfreq_max() const;
      83                 :            : 
      84                 :            :     Xapian::doccount get_termfreq_est() const;
      85                 :            : 
      86                 :            :     TermFreqs get_termfreq_est_using_stats(
      87                 :            :         const Xapian::Weight::Internal & stats) const;
      88                 :            : 
      89                 :            :     Xapian::docid get_docid() const;
      90                 :            : 
      91                 :            :     double get_weight(Xapian::termcount doclen,
      92                 :            :                       Xapian::termcount unique_terms) const;
      93                 :            : 
      94                 :            :     bool at_end() const;
      95                 :            : 
      96                 :            :     double recalc_maxweight();
      97                 :            : 
      98                 :          0 :     PositionList * read_position_list() {
      99                 :          0 :         return NULL;
     100                 :            :     }
     101                 :            : 
     102                 :            :     PostList* next(double w_min);
     103                 :            : 
     104                 :            :     PostList* skip_to(Xapian::docid, double w_min);
     105                 :            : 
     106                 :            :     std::string get_description() const;
     107                 :            : 
     108                 :            :     /** get_wdf() for MaxPostlist returns the sum of the wdfs of the
     109                 :            :      *  sub postlists which match the current docid.
     110                 :            :      *
     111                 :            :      *  The wdf isn't really meaningful in many situations, but if the lists
     112                 :            :      *  are being combined as a synonym we want the sum of the wdfs, so we do
     113                 :            :      *  that in general.
     114                 :            :      */
     115                 :            :     Xapian::termcount get_wdf() const;
     116                 :            : 
     117                 :            :     Xapian::termcount count_matching_subqs() const;
     118                 :            : };
     119                 :            : 
     120                 :            : #endif // XAPIAN_INCLUDED_MAXPOSTLIST_H

Generated by: LCOV version 1.11