xapian-core  2.0.0
vectortermlist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2011,2012,2017,2024 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (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 #ifndef XAPIAN_INCLUDED_VECTORTERMLIST_H
22 #define XAPIAN_INCLUDED_VECTORTERMLIST_H
23 
24 #include "xapian/types.h"
25 
26 #include "pack.h"
27 #include "termlist.h"
28 
38 class VectorTermList : public TermList {
40  std::string data;
41 
43  const char * p;
44 
47 
48  public:
49  template<typename I>
50  VectorTermList(I begin, I end) : num_terms(0)
51  {
52  // First calculate how much space we'll need so we can reserve it.
53  size_t total_size = 0;
54  for (I i = begin; i != end; ++i) {
55  ++num_terms;
56  const std::string & s = *i;
57  total_size += s.size() + 1;
58  if (s.size() >= 128) {
59  // Not a common case, so just assume the worst case rather than
60  // trying to carefully calculate the exact size.
61  total_size += 5;
62  }
63  }
64  data.reserve(total_size);
65 
66  // Now encode all the terms into data.
67  for (I i = begin; i != end; ++i) {
68  pack_string(data, *i);
69  }
70 
71  p = data.data();
72  }
73 
75 
76  Xapian::termcount get_wdf() const;
77 
79 
80  TermList * next();
81 
82  TermList* skip_to(std::string_view);
83 
85 
87 };
88 
89 #endif // XAPIAN_INCLUDED_VECTORTERMLIST_H
This class stores a list of terms.
TermList * skip_to(std::string_view)
Skip forward to the specified term.
VectorTermList(I begin, I end)
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
Xapian::termcount num_terms
The number of terms in the list.
const char * p
Pointer to the next term's data, or NULL if we are at end.
std::string data
The encoded terms.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
PositionList * positionlist_begin() const
Return PositionList for the current position.
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
TermList * next()
Advance the current position to the next term in the termlist.
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Abstract base class for termlists.
Definition: termlist.h:42
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
Pack types into strings and unpack them again.
void pack_string(std::string &s, std::string_view value)
Append an encoded std::string to a string.
Definition: pack.h:442
Abstract base class for termlists.
typedefs for Xapian