LCOV - code coverage report
Current view: top level - backends/glass - glass_metadata.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 21 27 77.8 %
Date: 2019-06-30 05:20:33 Functions: 6 9 66.7 %
Branches: 21 42 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file glass_metadata.cc
       2                 :            :  * @brief Access to metadata for a glass 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 "glass_metadata.h"
      25                 :            : 
      26                 :            : #include "glass_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                 :         32 : GlassMetadataTermList::GlassMetadataTermList(
      39                 :            :         intrusive_ptr<const Xapian::Database::Internal> database_,
      40                 :            :         GlassCursor * cursor_,
      41                 :            :         const string &prefix_)
      42 [ +  - ][ +  - ]:         32 :         : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
      43                 :            : {
      44                 :            :     LOGCALL_CTOR(DB, "GlassMetadataTermList", database_ | cursor_ | prefix_);
      45                 :            :     Assert(cursor);
      46                 :            :     // Seek to the first key before the first metadata key.
      47         [ +  - ]:         32 :     cursor->find_entry_lt(prefix);
      48                 :         32 : }
      49                 :            : 
      50                 :         96 : GlassMetadataTermList::~GlassMetadataTermList()
      51                 :            : {
      52                 :            :     LOGCALL_DTOR(DB, "GlassMetadataTermList");
      53         [ +  - ]:         32 :     delete cursor;
      54         [ -  + ]:         64 : }
      55                 :            : 
      56                 :            : Xapian::termcount
      57                 :          0 : GlassMetadataTermList::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                 :         68 : GlassMetadataTermList::get_termname() const
      66                 :            : {
      67                 :            :     LOGCALL(DB, string, "GlassMetadataTermList::get_termname", NO_ARGS);
      68                 :            :     Assert(!at_end());
      69                 :            :     Assert(!cursor->current_key.empty());
      70                 :            :     Assert(startswith(cursor->current_key, prefix));
      71                 :         68 :     RETURN(cursor->current_key.substr(2));
      72                 :            : }
      73                 :            : 
      74                 :            : Xapian::doccount
      75                 :          0 : GlassMetadataTermList::get_termfreq() const
      76                 :            : {
      77 [ #  # ][ #  # ]:          0 :     throw Xapian::InvalidOperationError("GlassMetadataTermList::get_termfreq() not meaningful");
                 [ #  # ]
      78                 :            : }
      79                 :            : 
      80                 :            : Xapian::termcount
      81                 :          0 : GlassMetadataTermList::get_collection_freq() const
      82                 :            : {
      83 [ #  # ][ #  # ]:          0 :     throw Xapian::InvalidOperationError("GlassMetadataTermList::get_collection_freq() not meaningful");
                 [ #  # ]
      84                 :            : }
      85                 :            : 
      86                 :            : TermList *
      87                 :         88 : GlassMetadataTermList::next()
      88                 :            : {
      89                 :            :     LOGCALL(DB, TermList *, "GlassMetadataTermList::next", NO_ARGS);
      90                 :            :     Assert(!at_end());
      91                 :            : 
      92                 :         88 :     cursor->next();
      93 [ +  + ][ +  + ]:         88 :     if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
                 [ +  + ]
      94                 :            :         // We've reached the end of the prefixed terms.
      95                 :         22 :         cursor->to_end();
      96                 :            :     }
      97                 :            : 
      98                 :         88 :     RETURN(NULL);
      99                 :            : }
     100                 :            : 
     101                 :            : TermList *
     102                 :         12 : GlassMetadataTermList::skip_to(const string &key)
     103                 :            : {
     104                 :            :     LOGCALL(DB, TermList *, "GlassMetadataTermList::skip_to", key);
     105                 :            :     Assert(!at_end());
     106                 :            : 
     107 [ +  - ][ +  - ]:         12 :     if (!cursor->find_entry_ge(string("\x00\xc0", 2) + key)) {
         [ +  - ][ +  + ]
     108                 :            :         // The exact term we asked for isn't there, so check if the next
     109                 :            :         // term after it also has the right prefix.
     110 [ +  - ][ +  + ]:          4 :         if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
                 [ +  + ]
     111                 :            :             // We've reached the end of the prefixed terms.
     112                 :          2 :             cursor->to_end();
     113                 :            :         }
     114                 :            :     }
     115                 :         12 :     RETURN(NULL);
     116                 :            : }
     117                 :            : 
     118                 :            : bool
     119                 :        100 : GlassMetadataTermList::at_end() const
     120                 :            : {
     121                 :            :     LOGCALL(DB, bool, "GlassMetadataTermList::at_end", NO_ARGS);
     122                 :        100 :     RETURN(cursor->after_end());
     123                 :            : }

Generated by: LCOV version 1.11