LCOV - code coverage report
Current view: top level - backends/honey - honey_alltermslist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 2 2 100.0 %
Date: 2019-06-30 05:20:33 Functions: 1 1 100.0 %
Branches: 2 4 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file honey_alltermslist.h
       2                 :            :  * @brief A termlist containing all terms in a honey database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2005,2007,2008,2009,2010,2011,2017 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_HONEY_ALLTERMSLIST_H
      23                 :            : #define XAPIAN_INCLUDED_HONEY_ALLTERMSLIST_H
      24                 :            : 
      25                 :            : #include "backends/alltermslist.h"
      26                 :            : #include "honey_database.h"
      27                 :            : #include "honey_postlist.h"
      28                 :            : 
      29                 :            : class HoneyCursor;
      30                 :            : 
      31                 :            : class HoneyAllTermsList : public AllTermsList {
      32                 :            :     /// Copying is not allowed.
      33                 :            :     HoneyAllTermsList(const HoneyAllTermsList&) = delete;
      34                 :            : 
      35                 :            :     /// Assignment is not allowed.
      36                 :            :     HoneyAllTermsList& operator=(const HoneyAllTermsList&) = delete;
      37                 :            : 
      38                 :            :     /** Reference to our database.
      39                 :            :      *
      40                 :            :      *  We need this to stop it being deleted, and so we can lazily initialise
      41                 :            :      *  @a cursor.
      42                 :            :      */
      43                 :            :     Xapian::Internal::intrusive_ptr<const HoneyDatabase> database;
      44                 :            : 
      45                 :            :     /** A cursor which runs through the postlist table reading termnames from
      46                 :            :      *  the keys.
      47                 :            :      *
      48                 :            :      *  The cursor is lazily initialised so that we can avoid the initial
      49                 :            :      *  positioning if skip_to() is the first action, and also so we can
      50                 :            :      *  avoid having to seek to the item before the first matching @a prefix
      51                 :            :      *  just so that the first next() advances us to where we want to start.
      52                 :            :      *
      53                 :            :      *  We also set this to NULL to signal the iterator has reached the
      54                 :            :      *  end - in this case database will also be NULL.
      55                 :            :      */
      56                 :            :     HoneyCursor* cursor = NULL;
      57                 :            : 
      58                 :            :     /// The termname at the current position.
      59                 :            :     std::string current_term;
      60                 :            : 
      61                 :            :     /// The prefix to restrict the terms to.
      62                 :            :     std::string prefix;
      63                 :            : 
      64                 :            :     /** The term frequency of the term at the current position.
      65                 :            :      *
      66                 :            :      *  If this value is zero, then we haven't read the term frequency or
      67                 :            :      *  collection frequency for the current term yet.  We need to call
      68                 :            :      *  read_termfreq_and_collfreq() to read these.
      69                 :            :      */
      70                 :            :     mutable Xapian::doccount termfreq = 0;
      71                 :            : 
      72                 :            :     /// The collection frequency of the term at the current position.
      73                 :            :     mutable Xapian::termcount collfreq;
      74                 :            : 
      75                 :            :     /// Read and cache the term frequency and collection frequency.
      76                 :            :     void read_termfreq_and_collfreq() const;
      77                 :            : 
      78                 :            :   public:
      79                 :         87 :     HoneyAllTermsList(const HoneyDatabase* database_,
      80                 :            :                       const std::string& prefix_)
      81 [ +  - ][ +  - ]:         87 :         : database(database_), prefix(prefix_) {}
      82                 :            : 
      83                 :            :     /// Destructor.
      84                 :            :     ~HoneyAllTermsList();
      85                 :            : 
      86                 :            :     Xapian::termcount get_approx_size() const;
      87                 :            : 
      88                 :            :     /** Returns the current termname.
      89                 :            :      *
      90                 :            :      *  Either next() or skip_to() must have been called before this
      91                 :            :      *  method can be called.
      92                 :            :      */
      93                 :            :     std::string get_termname() const;
      94                 :            : 
      95                 :            :     /** Returns the term frequency of the current term.
      96                 :            :      *
      97                 :            :      *  Either next() or skip_to() must have been called before this
      98                 :            :      *  method can be called.
      99                 :            :      */
     100                 :            :     Xapian::doccount get_termfreq() const;
     101                 :            : 
     102                 :            :     /** Returns the collection frequency of the current term.
     103                 :            :      *
     104                 :            :      *  Either next() or skip_to() must have been called before this
     105                 :            :      *  method can be called.
     106                 :            :      */
     107                 :            :     Xapian::termcount get_collection_freq() const;
     108                 :            : 
     109                 :            :     /// Advance to the next term in the list.
     110                 :            :     TermList* next();
     111                 :            : 
     112                 :            :     /// Advance to the first term which is >= term.
     113                 :            :     TermList* skip_to(const std::string &term);
     114                 :            : 
     115                 :            :     /// True if we're off the end of the list
     116                 :            :     bool at_end() const;
     117                 :            : };
     118                 :            : 
     119                 :            : #endif /* XAPIAN_INCLUDED_HONEY_ALLTERMSLIST_H */

Generated by: LCOV version 1.11