LCOV - code coverage report
Current view: top level - backends/honey - honey_termlisttable.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 0 30 0.0 %
Date: 2019-06-30 05:20:33 Functions: 0 1 0.0 %
Branches: 0 68 0.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file honey_termlisttable.cc
       2                 :            :  * @brief Subclass of HoneyTable which holds termlists.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2010,2018 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                 :            : #include <config.h>
      22                 :            : 
      23                 :            : #include "honey_termlisttable.h"
      24                 :            : 
      25                 :            : #include <xapian/document.h>
      26                 :            : #include <xapian/error.h>
      27                 :            : #include <xapian/termiterator.h>
      28                 :            : 
      29                 :            : #include "debuglog.h"
      30                 :            : #include "omassert.h"
      31                 :            : #include "pack.h"
      32                 :            : #include "stringutils.h"
      33                 :            : 
      34                 :            : #include <string>
      35                 :            : 
      36                 :            : using namespace std;
      37                 :            : 
      38                 :            : void
      39                 :          0 : HoneyTermListTable::set_termlist(Xapian::docid did,
      40                 :            :                                  const Xapian::Document & doc,
      41                 :            :                                  Xapian::termcount doclen)
      42                 :            : {
      43                 :            :     LOGCALL_VOID(DB, "HoneyTermListTable::set_termlist", did | doc | doclen);
      44                 :            : 
      45         [ #  # ]:          0 :     Xapian::doccount termlist_size = doc.termlist_count();
      46                 :            : 
      47         [ #  # ]:          0 :     string tag;
      48                 :            :     // FIXME: Need to encode value slots used here.  For now, just encode no
      49                 :            :     // slots as used.
      50         [ #  # ]:          0 :     tag += '\0';
      51                 :            : 
      52         [ #  # ]:          0 :     if (usual(termlist_size != 0)) {
      53         [ #  # ]:          0 :         pack_uint(tag, termlist_size - 1);
      54         [ #  # ]:          0 :         pack_uint(tag, doclen);
      55         [ #  # ]:          0 :         Xapian::TermIterator t = doc.termlist_begin();
      56         [ #  # ]:          0 :         string prev_term = *t;
      57                 :            : 
      58         [ #  # ]:          0 :         tag += prev_term.size();
      59 [ #  # ][ #  # ]:          0 :         pack_uint(tag, t.get_wdf());
      60         [ #  # ]:          0 :         tag += prev_term;
      61                 :            : 
      62 [ #  # ][ #  # ]:          0 :         while (++t != doc.termlist_end()) {
      63         [ #  # ]:          0 :             const string & term = *t;
      64                 :            :             // If there's a shared prefix with the previous term, we don't
      65                 :            :             // store it explicitly, but just store the length of the shared
      66                 :            :             // prefix.  In general, this is a big win.
      67         [ #  # ]:          0 :             size_t reuse = common_prefix_length(prev_term, term);
      68                 :            : 
      69                 :            :             // reuse must be <= prev_term.size(), and we know that value while
      70                 :            :             // decoding.  So if the wdf is small enough that we can multiply it
      71                 :            :             // by (prev_term.size() + 1), add reuse and fit the result in a
      72                 :            :             // byte, then we can pack reuse and the wdf into a single byte and
      73                 :            :             // save ourselves a byte.  We actually need to add one to the wdf
      74                 :            :             // before multiplying so that a wdf of 0 can be detected by the
      75                 :            :             // decoder.
      76         [ #  # ]:          0 :             Xapian::termcount wdf = t.get_wdf();
      77                 :            :             // If wdf >= 127, then we aren't going to be able to pack it in so
      78                 :            :             // don't even try to avoid any risk of the calculation overflowing
      79                 :            :             // and making us think we can.
      80                 :            :             size_t packed;
      81   [ #  #  #  # ]:          0 :             if (wdf < 127 &&
                 [ #  # ]
      82                 :          0 :                 (packed = (wdf + 1) * (prev_term.size() + 1) + reuse) < 256) {
      83                 :            :                 // We can pack the wdf into the same byte.
      84         [ #  # ]:          0 :                 tag += char(packed);
      85                 :            :             } else {
      86         [ #  # ]:          0 :                 tag += char(reuse);
      87         [ #  # ]:          0 :                 pack_uint(tag, wdf);
      88                 :            :             }
      89         [ #  # ]:          0 :             tag += char(term.size() - reuse);
      90         [ #  # ]:          0 :             tag.append(term.data() + reuse, term.size() - reuse);
      91                 :            : 
      92 [ #  # ][ #  # ]:          0 :             prev_term = *t;
      93                 :          0 :         }
      94                 :            :     } else {
      95                 :            :         Assert(doclen == 0);
      96                 :            :         Assert(doc.termlist_begin() == doc.termlist_end());
      97                 :            :     }
      98                 :            : 
      99 [ #  # ][ #  # ]:          0 :     if (rare(tag.size() == 1 && tag[0] == '\0')) {
         [ #  # ][ #  # ]
     100                 :            :         // No slots used or terms.
     101         [ #  # ]:          0 :         del(make_key(did));
     102                 :            :     } else {
     103 [ #  # ][ #  # ]:          0 :         add(make_key(did), tag);
     104                 :          0 :     }
     105                 :          0 : }

Generated by: LCOV version 1.11