2 * @brief Xapian::Weight base class
4 /* Copyright (C) 2007,2008,2009,2014,2017,2019 Olly Betts
5 * Copyright (C) 2009 Lemur Consulting Ltd
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.
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.
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
24 #include "xapian/weight.h"
26 #include "api/leafpostlist.h"
27 #include "weightinternal.h"
32 #include "xapian/error.h"
39 Weight::init_(const Internal
& stats
, Xapian::termcount query_length
)
41 LOGCALL_VOID(MATCH
, "Weight::init_", stats
| query_length
);
42 collection_size_
= stats
.collection_size
;
43 rset_size_
= stats
.rset_size
;
44 if (stats_needed
& AVERAGE_LENGTH
)
45 average_length_
= stats
.get_average_length();
46 if (stats_needed
& DOC_LENGTH_MAX
)
47 doclength_upper_bound_
= stats
.db
.get_doclength_upper_bound();
48 if (stats_needed
& DOC_LENGTH_MIN
)
49 doclength_lower_bound_
= stats
.db
.get_doclength_lower_bound();
54 query_length_
= query_length
;
60 Weight::init_(const Internal
& stats
, Xapian::termcount query_length
,
61 const string
& term
, Xapian::termcount wqf
, double factor
,
64 LOGCALL_VOID(MATCH
, "Weight::init_", stats
| query_length
| term
| wqf
| factor
| postlist_void
);
65 collection_size_
= stats
.collection_size
;
66 rset_size_
= stats
.rset_size
;
67 if (stats_needed
& AVERAGE_LENGTH
)
68 average_length_
= stats
.get_average_length();
69 if (stats_needed
& DOC_LENGTH_MAX
)
70 doclength_upper_bound_
= stats
.db
.get_doclength_upper_bound();
71 if (stats_needed
& DOC_LENGTH_MIN
)
72 doclength_lower_bound_
= stats
.db
.get_doclength_lower_bound();
73 if (stats_needed
& WDF_MAX
) {
74 if (usual(postlist_void
!= nullptr)) {
75 auto postlist
= static_cast<LeafPostList
*>(postlist_void
);
76 wdf_upper_bound_
= postlist
->get_wdf_upper_bound();
78 wdf_upper_bound_
= stats
.db
.get_wdf_upper_bound(term
);
81 if (stats_needed
& (TERMFREQ
| RELTERMFREQ
| COLLECTION_FREQ
)) {
82 bool ok
= stats
.get_stats(term
,
83 termfreq_
, reltermfreq_
, collectionfreq_
);
87 query_length_
= query_length
;
93 Weight::init_(const Internal
& stats
, Xapian::termcount query_length
,
94 const string
& term
, Xapian::termcount wqf
, double factor
)
96 init_(stats
, query_length
, term
, wqf
, factor
, nullptr);
100 Weight::init_(const Internal
& stats
, Xapian::termcount query_length
,
101 double factor
, Xapian::doccount termfreq
,
102 Xapian::doccount reltermfreq
, Xapian::termcount collection_freq
)
104 LOGCALL_VOID(MATCH
, "Weight::init_", stats
| query_length
| factor
| termfreq
| reltermfreq
| collection_freq
);
106 collection_size_
= stats
.collection_size
;
107 rset_size_
= stats
.rset_size
;
108 if (stats_needed
& AVERAGE_LENGTH
)
109 average_length_
= stats
.get_average_length();
110 if (stats_needed
& (DOC_LENGTH_MAX
| WDF_MAX
)) {
111 doclength_upper_bound_
= stats
.db
.get_doclength_upper_bound();
112 // The doclength is an upper bound on the wdf. This is obviously true
113 // for normal terms, but SynonymPostList ensures that it is also true
114 // for synonym terms by clamping the wdf values returned to the
117 // (This clamping is only actually necessary in cases where a constituent
118 // term of the synonym is repeated.)
119 wdf_upper_bound_
= doclength_upper_bound_
;
121 if (stats_needed
& DOC_LENGTH_MIN
)
122 doclength_lower_bound_
= stats
.db
.get_doclength_lower_bound();
124 termfreq_
= termfreq
;
125 reltermfreq_
= reltermfreq
;
126 query_length_
= query_length
;
127 collectionfreq_
= collection_freq
;
132 Weight::~Weight() { }
141 Weight::serialise() const
143 throw Xapian::UnimplementedError("serialise() not supported for this Xapian::Weight subclass");
147 Weight::unserialise(const string
&) const
149 throw Xapian::UnimplementedError("unserialise() not supported for this Xapian::Weight subclass");