xapian-core  2.0.0
leafpostlist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007-2024 Olly Betts
5  * Copyright (C) 2009 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (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, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_LEAFPOSTLIST_H
23 #define XAPIAN_INCLUDED_LEAFPOSTLIST_H
24 
25 #include "postlist.h"
26 
27 #include <algorithm>
28 #include <string>
29 #include <string_view>
30 
31 namespace Xapian {
32  class Weight;
33 }
34 
40 class LeafPostList : public PostList {
42  void operator=(const LeafPostList &) = delete;
43 
45  LeafPostList(const LeafPostList &) = delete;
46 
47  protected:
48  const Xapian::Weight* weight = nullptr;
49 
51  std::string term;
52 
58 
60  explicit LeafPostList(std::string_view term_)
61  : term(term_) { }
62 
63  public:
64  ~LeafPostList();
65 
71 
81  void set_termweight(const Xapian::Weight * weight_) {
82  // This method shouldn't be called more than once on the same object.
83  Assert(!weight);
84  weight = weight_;
85  }
86 
89  Xapian::termcount qlen,
91  double factor,
92  const Xapian::Database::Internal* shard)
93  {
94  weight_->init_(*stats, qlen, term, wqf, factor, shard, this);
95  // There should be an existing LazyWeight set already.
96  Assert(weight);
97  const Xapian::Weight * const_weight_ = weight_;
98  std::swap(weight, const_weight_);
99  delete const_weight_;
100  // We get such terms from the database so they should exist.
101  Assert(get_termfreq() > 0);
102  double result = weight->get_maxpart();
103  double& max_part = stats->termfreqs[term].max_part;
104  max_part = std::max(max_part, result);
105  return result;
106  }
107 
108  double get_weight(Xapian::termcount doclen,
109  Xapian::termcount unique_terms,
110  Xapian::termcount wdfdocmax) const;
111 
112  double recalc_maxweight();
113 
115 
116  void gather_position_lists(OrPositionList* orposlist);
117 
141  virtual bool open_nearby_postlist(std::string_view term_,
142  bool need_read_pos,
143  LeafPostList*& pl) const;
144 
146 
148  const std::string& get_term() const { return term; }
149 
155  void set_term(std::string_view term_) { term = term_; }
156 };
157 
158 #endif // XAPIAN_INCLUDED_LEAFPOSTLIST_H
Abstract base class for leaf postlists.
Definition: leafpostlist.h:40
Xapian::termcount get_collfreq() const
Get the collection frequency of the term.
Definition: leafpostlist.h:70
Xapian::termcount collfreq
The collection frequency of the term.
Definition: leafpostlist.h:57
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
Definition: leafpostlist.cc:57
const std::string & get_term() const
Get the term name.
Definition: leafpostlist.h:148
void set_term(std::string_view term_)
Set the term name.
Definition: leafpostlist.h:155
void operator=(const LeafPostList &)=delete
Don't allow assignment.
void set_termweight(const Xapian::Weight *weight_)
Set the weighting scheme to use during matching.
Definition: leafpostlist.h:81
virtual Xapian::termcount get_wdf_upper_bound() const =0
const Xapian::Weight * weight
Definition: leafpostlist.h:48
void gather_position_lists(OrPositionList *orposlist)
Gather PositionList* objects for a subtree.
Definition: leafpostlist.cc:63
LeafPostList(const LeafPostList &)=delete
Don't allow copying.
double resolve_lazy_termweight(Xapian::Weight *weight_, Xapian::Weight::Internal *stats, Xapian::termcount qlen, Xapian::termcount wqf, double factor, const Xapian::Database::Internal *shard)
Definition: leafpostlist.h:87
double get_weight(Xapian::termcount doclen, Xapian::termcount unique_terms, Xapian::termcount wdfdocmax) const
Return the weight contribution for the current position.
Definition: leafpostlist.cc:39
LeafPostList(std::string_view term_)
Only constructable as a base class for derived classes.
Definition: leafpostlist.h:60
std::string term
The term name for this postlist (empty for an alldocs postlist).
Definition: leafpostlist.h:51
virtual bool open_nearby_postlist(std::string_view term_, bool need_read_pos, LeafPostList *&pl) const
Open another postlist from the same database.
Definition: leafpostlist.cc:69
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
Definition: leafpostlist.cc:51
Virtual base class for Database internals.
Abstract base class for postlists.
Definition: postlist.h:40
Xapian::doccount get_termfreq() const
Get an estimate of the number of documents this PostList will return.
Definition: postlist.h:67
Class to hold statistics for a given collection.
std::map< std::string, TermFreqs, std::less<> > termfreqs
Map of term frequencies and relevant term frequencies for the collection.
Abstract base class for weighting schemes.
Definition: weight.h:38
virtual double get_maxpart() const =0
Return an upper bound on what get_sumpart() can return for any document.
void init_(const Internal &stats, Xapian::termcount query_len_, const std::string &term, Xapian::termcount wqf_, double factor, const Xapian::Database::Internal *shard, void *postlist)
Definition: weight.cc:76
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
#define Assert(COND)
Definition: omassert.h:122
Abstract base class for postlists.