LCOV - code coverage report
Current view: top level - backends/honey - honey_metadata.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7028d852e609 Lines: 0 36 0.0 %
Date: 2019-02-17 14:59:59 Functions: 0 9 0.0 %
Branches: 0 58 0.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file honey_metadata.cc
       2                 :            :  * @brief Access to metadata for a honey database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2004,2005,2006,2007,2008,2009,2010,2011,2017 Olly Betts
       5                 :            :  * Copyright (C) 2008 Lemur Consulting Ltd
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (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 "honey_metadata.h"
      25                 :            : 
      26                 :            : #include "honey_cursor.h"
      27                 :            : 
      28                 :            : #include "backends/databaseinternal.h"
      29                 :            : #include "debuglog.h"
      30                 :            : #include "omassert.h"
      31                 :            : #include "stringutils.h"
      32                 :            : 
      33                 :            : #include "xapian/error.h"
      34                 :            : 
      35                 :            : using namespace std;
      36                 :            : using Xapian::Internal::intrusive_ptr;
      37                 :            : 
      38                 :          0 : HoneyMetadataTermList::HoneyMetadataTermList(
      39                 :            :         const Xapian::Database::Internal* database_,
      40                 :            :         HoneyCursor* cursor_,
      41                 :            :         const string& prefix_)
      42 [ #  # ][ #  # ]:          0 :     : database(database_), cursor(cursor_), prefix(string("\0", 2) + prefix_)
      43                 :            : {
      44                 :            :     LOGCALL_CTOR(DB, "HoneyMetadataTermList", database_ | cursor_ | prefix_);
      45                 :            :     Assert(cursor);
      46                 :            :     // Set the cursor to its end to signal we haven't started yet.
      47                 :          0 :     cursor->to_end();
      48                 :          0 : }
      49                 :            : 
      50                 :          0 : HoneyMetadataTermList::~HoneyMetadataTermList()
      51                 :            : {
      52                 :            :     LOGCALL_DTOR(DB, "HoneyMetadataTermList");
      53         [ #  # ]:          0 :     delete cursor;
      54         [ #  # ]:          0 : }
      55                 :            : 
      56                 :            : Xapian::termcount
      57                 :          0 : HoneyMetadataTermList::get_approx_size() const
      58                 :            : {
      59                 :            :     // Very approximate!  This is only used to build a balanced or tree, so
      60                 :            :     // at least we'll get an even tree by returning a constant answer.
      61                 :          0 :     return 1;
      62                 :            : }
      63                 :            : 
      64                 :            : string
      65                 :          0 : HoneyMetadataTermList::get_termname() const
      66                 :            : {
      67                 :            :     LOGCALL(DB, string, "HoneyMetadataTermList::get_termname", NO_ARGS);
      68                 :            :     Assert(!at_end());
      69                 :            :     Assert(!cursor->current_key.empty());
      70                 :            :     Assert(startswith(cursor->current_key, prefix));
      71                 :          0 :     RETURN(cursor->current_key.substr(2));
      72                 :            : }
      73                 :            : 
      74                 :            : Xapian::doccount
      75                 :          0 : HoneyMetadataTermList::get_termfreq() const
      76                 :            : {
      77                 :            :     throw Xapian::InvalidOperationError("HoneyMetadataTermList::get_termfreq() "
      78 [ #  # ][ #  # ]:          0 :                                         "not meaningful");
                 [ #  # ]
      79                 :            : }
      80                 :            : 
      81                 :            : Xapian::termcount
      82                 :          0 : HoneyMetadataTermList::get_collection_freq() const
      83                 :            : {
      84                 :            :     throw Xapian::InvalidOperationError("HoneyMetadataTermList::"
      85                 :            :                                         "get_collection_freq() "
      86 [ #  # ][ #  # ]:          0 :                                         "not meaningful");
                 [ #  # ]
      87                 :            : }
      88                 :            : 
      89                 :            : TermList *
      90                 :          0 : HoneyMetadataTermList::next()
      91                 :            : {
      92                 :            :     LOGCALL(DB, TermList *, "HoneyMetadataTermList::next", NO_ARGS);
      93                 :            :     Assert(!at_end());
      94                 :            : 
      95         [ #  # ]:          0 :     if (cursor->after_end()) {
      96                 :            :         // This is the first action on a new HoneyMetadataTermList.
      97         [ #  # ]:          0 :         if (cursor->find_entry_ge(prefix))
      98                 :          0 :             RETURN(NULL);
      99                 :            :     } else {
     100                 :          0 :         cursor->next();
     101                 :            :     }
     102 [ #  # ][ #  # ]:          0 :     if (cursor->after_end() || !startswith(cursor->current_key, prefix)) {
                 [ #  # ]
     103                 :            :         // We've reached the end of the prefixed terms.
     104         [ #  # ]:          0 :         delete cursor;
     105                 :          0 :         cursor = NULL;
     106                 :            :     }
     107                 :            : 
     108                 :          0 :     RETURN(NULL);
     109                 :            : }
     110                 :            : 
     111                 :            : TermList *
     112                 :          0 : HoneyMetadataTermList::skip_to(const string &key)
     113                 :            : {
     114                 :            :     LOGCALL(DB, TermList *, "HoneyMetadataTermList::skip_to", key);
     115                 :            :     Assert(!at_end());
     116                 :            : 
     117                 :            :     // k is the table key (key is the user metadata key).
     118         [ #  # ]:          0 :     string k(2, '\0');
     119         [ #  # ]:          0 :     k += key;
     120 [ #  # ][ #  # ]:          0 :     if (cursor->after_end() && prefix > k) {
         [ #  # ][ #  # ]
     121                 :            :         // This is the first action on a new HoneySynonymTermList and we were
     122                 :            :         // asked to skip to a key before the prefix - this ought to leave us
     123                 :            :         // on the first key with the specified prefix.
     124         [ #  # ]:          0 :         k = prefix;
     125                 :            :     }
     126                 :            : 
     127 [ #  # ][ #  # ]:          0 :     if (!cursor->find_entry_ge(k)) {
     128                 :            :         // The exact key we asked for isn't there, so check if the next
     129                 :            :         // key after it also has the right prefix.
     130 [ #  # ][ #  # ]:          0 :         if (cursor->after_end() || !startswith(cursor->current_key, prefix)) {
                 [ #  # ]
     131                 :            :             // We've reached the end of the prefixed keys.
     132         [ #  # ]:          0 :             delete cursor;
     133                 :          0 :             cursor = NULL;
     134                 :            :         }
     135                 :            :     }
     136                 :          0 :     RETURN(NULL);
     137                 :            : }
     138                 :            : 
     139                 :            : bool
     140                 :          0 : HoneyMetadataTermList::at_end() const
     141                 :            : {
     142                 :            :     LOGCALL(DB, bool, "HoneyMetadataTermList::at_end", NO_ARGS);
     143                 :          0 :     RETURN(cursor == NULL);
     144                 :            : }

Generated by: LCOV version 1.11