xapian-core  2.0.0
synonympostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright 2007,2009 Lemur Consulting Ltd
5  * Copyright 2009,2011,2014,2016,2017,2018,2024 Olly Betts
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 #include <config.h>
23 
24 #include "synonympostlist.h"
25 
26 #include "debuglog.h"
27 #include "omassert.h"
28 #include "postlisttree.h"
29 
30 using namespace std;
31 
33 {
34  delete wt;
35 }
36 
37 void
39 {
40  delete wt;
41  wt = wt_;
42  want_wdf = wt->get_sumpart_needs_wdf_();
43  want_wdfdocmax = wt->get_sumpart_needs_wdfdocmax_();
44 }
45 
46 PostList *
47 SynonymPostList::next(double w_min)
48 {
49  LOGCALL(MATCH, PostList *, "SynonymPostList::next", w_min);
50  (void)w_min;
52 }
53 
54 PostList *
56 {
57  LOGCALL(MATCH, PostList *, "SynonymPostList::skip_to", did | w_min);
58  (void)w_min;
60 }
61 
62 double
64  Xapian::termcount unique_terms,
65  Xapian::termcount wdfdocmax) const
66 {
67  LOGCALL(MATCH, double, "SynonymPostList::get_weight", doclen | unique_terms);
68  Xapian::termcount wdf = 0;
69  if (want_wdf) {
71  if (needs_doclen) {
72  // The wdf for a synonym is approximated and in some cases it could
73  // exceed the document length. For example, this can currently
74  // occur if the query below OP_SYNONYM contains a term more than
75  // once as the wdf of each occurrence is summed.
76  //
77  // This is unhelpful since it's reasonable for weighting algorithms
78  // to optimise by assuming that get_wdf() will never return more
79  // than doclen, since doclen is the sum of the wdfs.
80  //
81  // If the weighting scheme doesn't request the document length then
82  // it can't be making this assumption, so we simply clamp the wdf
83  // value to doclen if both are requested, since the clamping is
84  // cheap in this case as we already have both values.
85  if (wdf > doclen) wdf = doclen;
86  }
87  }
88  if (want_wdfdocmax) {
89  // FIXME: Can we avoid this?
90  if (doclen == 0) {
91  doclen = pltree->get_doclength(pl->get_docid());
92  }
93  wdfdocmax = doclen;
94  }
95  RETURN(wt->get_sumpart(wdf, doclen, unique_terms, wdfdocmax));
96 }
97 
98 double
100 {
101  LOGCALL(MATCH, double, "SynonymPostList::recalc_maxweight", NO_ARGS);
102  RETURN(wt->get_maxpart());
103 }
104 
107 {
108  return 1;
109 }
110 
111 string
113 {
114  string desc = "SynonymPostList(";
115  desc += pl->get_description();
116  desc += ')';
117  return desc;
118 }
void set_weight(const Xapian::Weight *wt_)
Set the weight object to be used for the synonym postlist.
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
double get_weight(Xapian::termcount doclen, Xapian::termcount unique_terms, Xapian::termcount wdfdocmax) const
Return the weight contribution for the current position.
PostList * skip_to(Xapian::docid did, double w_min)
Skip forward to the specified docid.
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
std::string get_description() const
Return a string description of this object.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
PostList * skip_to(Xapian::docid, double w_min)
Skip forward to the specified docid.
Abstract base class for postlists.
Definition: postlist.h:40
PostList * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:168
Abstract base class for weighting schemes.
Definition: weight.h:38
bool get_sumpart_needs_wdf_() const
Definition: weight.h:484
Debug logging macros.
#define RETURN(...)
Definition: debuglog.h:484
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:478
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Various assertion macros.
Class for managing a tree of PostList objects.
Combine subqueries, weighting as if they are synonyms.