xapian-core  1.4.26
leafpostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2009,2011,2013,2014 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, 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 "xapian/weight.h"
25 
26 #include "leafpostlist.h"
27 #include "matcher/orpositionlist.h"
28 #include "omassert.h"
29 #include "debuglog.h"
30 
31 using namespace std;
32 
34 {
35  delete weight;
36 }
37 
40 {
41  return get_termfreq();
42 }
43 
46 {
47  return get_termfreq();
48 }
49 
52 {
53  return get_termfreq();
54 }
55 
56 void
58 {
59  // This method shouldn't be called more than once on the same object.
60  Assert(!weight);
61  weight = weight_;
62  need_doclength = weight->get_sumpart_needs_doclength_();
63  need_unique_terms = weight->get_sumpart_needs_uniqueterms_();
64 }
65 
66 double
68 {
69  return weight ? weight->get_maxpart() : 0;
70 }
71 
72 double
74 {
75  if (!weight) return 0;
76  Xapian::termcount doclen = 0, unique_terms = 0;
77  // Fetching the document length and number of unique terms is work we can
78  // avoid if the weighting scheme doesn't use them.
79  if (need_doclength)
80  doclen = get_doclength();
81  if (need_unique_terms)
82  unique_terms = get_unique_terms();
83  double sumpart = weight->get_sumpart(get_wdf(), doclen, unique_terms);
84  AssertRel(sumpart, <=, weight->get_maxpart());
85  return sumpart;
86 }
87 
88 double
90 {
92 }
93 
96  const Xapian::Weight::Internal & stats) const
97 {
98  LOGCALL(MATCH, TermFreqs, "LeafPostList::get_termfreq_est_using_stats", stats);
99  if (term.empty()) {
101  stats.rset_size,
102  stats.total_length));
103  }
104  map<string, TermFreqs>::const_iterator i = stats.termfreqs.find(term);
105  Assert(i != stats.termfreqs.end());
106  RETURN(i->second);
107 }
108 
111 {
112  return weight ? 1 : 0;
113 }
114 
115 void
117 {
118  orposlist->add_poslist(read_position_list());
119 }
120 
121 LeafPostList *
122 LeafPostList::open_nearby_postlist(const std::string &) const
123 {
124  return NULL;
125 }
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
TermFreqs get_termfreq_est_using_stats(const Xapian::Weight::Internal &stats) const
Get an estimate for the termfreq and reltermfreq, given the stats.
Definition: leafpostlist.cc:95
#define AssertRel(A, REL, B)
Definition: omassert.h:123
double weight
The weight of a document or term.
Definition: types.h:122
Xapian::doccount get_termfreq_max() const
Get an upper bound on the number of documents indexed by this term.
Definition: leafpostlist.cc:45
Xapian::doccount get_termfreq_est() const
Get an estimate of the number of documents indexed by this term.
Definition: leafpostlist.cc:51
STL namespace.
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
Definition: leafpostlist.cc:89
Abstract base class for leaf postlists.
Definition: leafpostlist.h:39
Abstract base class for leaf postlists.
double get_maxweight() const
Return an upper bound on what get_weight() can return.
Definition: leafpostlist.cc:67
std::map< std::string, TermFreqs > termfreqs
Map of term frequencies and relevant term frequencies for the collection.
Xapian::doccount collection_size
Number of documents in the collection.
Xapian::doccount rset_size
Number of relevant documents in the collection.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
void set_termweight(const Xapian::Weight *weight_)
Set the weighting scheme to use during matching.
Definition: leafpostlist.cc:57
Xapian::doccount get_termfreq_min() const
Get a lower bound on the number of documents indexed by this term.
Definition: leafpostlist.cc:39
Class to hold statistics for a given collection.
void add_poslist(PositionList *poslist)
virtual LeafPostList * open_nearby_postlist(const std::string &term_) const
Open another postlist from the same database.
void gather_position_lists(OrPositionList *orposlist)
Gather PositionList* objects for a subtree.
Weighting scheme API.
The frequencies for a term.
double get_weight() const
Return the weight contribution for the current position.
Definition: leafpostlist.cc:73
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Various assertion macros.
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
Xapian::totallength total_length
Total length of all documents in the collection.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487
Merge two PositionList objects using an OR operation.
Abstract base class for weighting schemes.
Definition: weight.h:35