LCOV - code coverage report
Current view: top level - backends/honey - honey_termlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core fcfb185a9dd5 Lines: 5 5 100.0 %
Date: 2019-04-18 16:33:14 Functions: 3 3 100.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file honey_termlist.h
       2                 :            :  * @brief A TermList in a honey database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2010,2011 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2 of the License, or
       9                 :            :  * (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 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef XAPIAN_INCLUDED_HONEY_TERMLIST_H
      22                 :            : #define XAPIAN_INCLUDED_HONEY_TERMLIST_H
      23                 :            : 
      24                 :            : #include <algorithm>
      25                 :            : #include <string>
      26                 :            : 
      27                 :            : #include "xapian/intrusive_ptr.h"
      28                 :            : #include <xapian/positioniterator.h>
      29                 :            : #include <xapian/types.h>
      30                 :            : 
      31                 :            : namespace Xapian {
      32                 :            :     namespace Internal {
      33                 :            :         class ExpandStats;
      34                 :            :     }
      35                 :            : }
      36                 :            : 
      37                 :            : #include "honey_database.h"
      38                 :            : #include "api/termlist.h"
      39                 :            : #include "honey_table.h"
      40                 :            : 
      41                 :            : /// A TermList in a honey database.
      42         [ -  + ]:       2002 : class HoneyTermList : public TermList {
      43                 :            :     /// Don't allow assignment.
      44                 :            :     void operator=(const HoneyTermList &);
      45                 :            : 
      46                 :            :     /// Don't allow copying.
      47                 :            :     HoneyTermList(const HoneyTermList &);
      48                 :            : 
      49                 :            :     /// The database we're reading data from.
      50                 :            :     Xapian::Internal::intrusive_ptr<const HoneyDatabase> db;
      51                 :            : 
      52                 :            :     /// The document id that this TermList is for.
      53                 :            :     Xapian::docid did;
      54                 :            : 
      55                 :            :     /// The length of document @a did.
      56                 :            :     Xapian::termcount doclen;
      57                 :            : 
      58                 :            :     /// The number of entries in this termlist.
      59                 :            :     Xapian::termcount termlist_size;
      60                 :            : 
      61                 :            :     /// The tag value from the termlist table which holds the encoded termlist.
      62                 :            :     std::string data;
      63                 :            : 
      64                 :            :     /** Current position with the encoded tag value held in @a data.
      65                 :            :      *
      66                 :            :      *  If we've iterated to the end of the list, this gets set to NULL.
      67                 :            :      */
      68                 :            :     const char *pos;
      69                 :            : 
      70                 :            :     /// Pointer to the end of the encoded tag value.
      71                 :            :     const char *end;
      72                 :            : 
      73                 :            :     /// The termname at the current position.
      74                 :            :     std::string current_term;
      75                 :            : 
      76                 :            :     /// The wdf for the term at the current position.
      77                 :            :     Xapian::termcount current_wdf;
      78                 :            : 
      79                 :            :     /** The term frequency for the term at the current position.
      80                 :            :      *
      81                 :            :      *  This will have the value 0 if the term frequency has not yet been
      82                 :            :      *  looked up in the database (so it needs to be mutable).
      83                 :            :      */
      84                 :            :     mutable Xapian::doccount current_termfreq;
      85                 :            : 
      86                 :            :   public:
      87                 :            :     /// Create a new HoneyTermList object for document @a did_ in DB @a db_
      88                 :            :     HoneyTermList(const HoneyDatabase* db_, Xapian::docid did_);
      89                 :            : 
      90                 :            :     /** Return the length of this document.
      91                 :            :      *
      92                 :            :      *  This is a non-virtual method, used by HoneyDatabase.
      93                 :            :      */
      94                 :            :     Xapian::termcount get_doclength() const {
      95                 :            :         return doclen;
      96                 :            :     }
      97                 :            : 
      98                 :            :     /** Return the number of entries in this termlist.
      99                 :            :      *
     100                 :            :      *  This is a non-virtual method, used by HoneyDatabase.
     101                 :            :      */
     102                 :        235 :     Xapian::termcount size() const {
     103                 :        235 :         return termlist_size;
     104                 :            :     }
     105                 :            : 
     106                 :            :     /** Return the number of unique terms.
     107                 :            :      *
     108                 :            :      *  This is a non-virtual method, used by HoneyDatabase.
     109                 :            :      */
     110                 :        531 :     Xapian::termcount get_unique_terms() const {
     111                 :            :         // We approximate get_unique_terms() by the length of the termlist
     112                 :            :         // (which counts boolean terms too) but clamp the result to be no
     113                 :            :         // larger than the document length.
     114                 :        531 :         return std::min(termlist_size, doclen);
     115                 :            :     }
     116                 :            : 
     117                 :            :     /** Return approximate size of this termlist.
     118                 :            :      *
     119                 :            :      *  For a HoneyTermList, this value will always be exact.
     120                 :            :      */
     121                 :            :     Xapian::termcount get_approx_size() const;
     122                 :            : 
     123                 :            :     /// Collate weighting information for the current term.
     124                 :            :     void accumulate_stats(Xapian::Internal::ExpandStats& stats) const;
     125                 :            : 
     126                 :            :     /// Return the termname at the current position.
     127                 :            :     std::string get_termname() const;
     128                 :            : 
     129                 :            :     /// Return the wdf for the term at the current position.
     130                 :            :     Xapian::termcount get_wdf() const;
     131                 :            : 
     132                 :            :     /** Return the term frequency for the term at the current position.
     133                 :            :      *
     134                 :            :      *  In order to be able to support updating databases efficiently, we can't
     135                 :            :      *  store this value in the termlist table, so it has to be read from the
     136                 :            :      *  postlist table, which is relatively expensive (compared to reading the
     137                 :            :      *  wdf for example).
     138                 :            :      */
     139                 :            :     Xapian::doccount get_termfreq() const;
     140                 :            : 
     141                 :            :     /** Advance the current position to the next term in the termlist.
     142                 :            :      *
     143                 :            :      *  The list starts before the first term in the list, so next(), skip_to()
     144                 :            :      *  or check() must be called before any methods which need the context of
     145                 :            :      *  the current position.
     146                 :            :      *
     147                 :            :      *  @return Always returns 0 for a HoneyTermList.
     148                 :            :      */
     149                 :            :     TermList* next();
     150                 :            : 
     151                 :            :     TermList* skip_to(const std::string& term);
     152                 :            : 
     153                 :            :     /// Return true if the current position is past the last term in this list.
     154                 :            :     bool at_end() const;
     155                 :            : 
     156                 :            :     /// Return the length of the position list for the current position.
     157                 :            :     Xapian::termcount positionlist_count() const;
     158                 :            : 
     159                 :            :     /// Return a PositionIterator for the current position.
     160                 :            :     PositionList* positionlist_begin() const;
     161                 :            : };
     162                 :            : 
     163                 :            : #endif // XAPIAN_INCLUDED_HONEY_TERMLIST_H

Generated by: LCOV version 1.11