xapian-core  2.0.0
remote_termlist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2018,2024 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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 
23 #include "remote_termlist.h"
24 
25 #include "expand/expandweight.h"
26 #include "omassert.h"
27 #include "pack.h"
28 #include "remote-database.h"
29 
30 using namespace std;
31 
34 {
35  // Used for query expansion with remote databases. FIXME: Rework that and
36  // drop this?
37  return num_entries;
38 }
39 
40 void
42 {
43  // Used for query expansion with remote databases. FIXME: Rework that and
44  // drop this?
45  Assert(!data.empty());
46  stats.accumulate(shard_index,
47  current_wdf, doclen, current_termfreq, db_size);
48 }
49 
52 {
53  Assert(!data.empty());
54  return current_wdf;
55 }
56 
59 {
60  Assert(!data.empty());
61  return current_termfreq;
62 }
63 
64 TermList*
66 {
67  if (!p) {
68  p = data.data();
69  }
70  const char* p_end = data.data() + data.size();
71  if (p == p_end) {
72  return this;
73  }
74  current_term.resize(size_t(static_cast<unsigned char>(*p++)));
75  if (!unpack_string_append(&p, p_end, current_term) ||
76  !unpack_uint(&p, p_end, &current_wdf) ||
77  !unpack_uint(&p, p_end, &current_termfreq)) {
79  }
80  return NULL;
81 }
82 
83 TermList*
84 RemoteTermList::skip_to(std::string_view term)
85 {
86  if (!p) {
88  return this;
89  }
90  while (current_term < term) {
92  return this;
93  }
94  return NULL;
95 }
96 
99 {
100  return db->positionlist_count(did, current_term);
101 }
102 
105 {
106  return db->open_position_list(did, current_term);
107 }
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
void accumulate_stats(Xapian::Internal::ExpandStats &stats) const
Collate weighting information for the current term.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
TermList * next()
Advance the current position to the next term in the termlist.
TermList * skip_to(std::string_view term)
Skip forward to the specified term.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
PositionList * positionlist_begin() const
Return PositionList for the current position.
Collates statistics while calculating term weight in an ESet.
Definition: expandweight.h:37
void accumulate(size_t shard_index, Xapian::termcount wdf, Xapian::termcount doclen, Xapian::doccount subtf, Xapian::doccount subdbsize)
Definition: expandweight.h:71
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Abstract base class for termlists.
Definition: termlist.h:42
string term
PositionList * p
Collate statistics and calculate the term weights for the ESet.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
Various assertion macros.
#define Assert(COND)
Definition: omassert.h:122
void unpack_throw_serialisation_error(const char *p)
Throw appropriate SerialisationError.
Definition: pack.cc:29
Pack types into strings and unpack them again.
bool unpack_string_append(const char **p, const char *end, std::string &result)
Decode a std::string from a string and append.
Definition: pack.h:493
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
Definition: pack.h:346
RemoteDatabase is the baseclass for remote database implementations.
Iterate terms in a remote document.