Ticket #433: matchspy_api_changes_experiment.patch
File matchspy_api_changes_experiment.patch, 4.2 KB (added by , 15 years ago) |
---|
-
matcher/multimatch.cc
190 190 * 191 191 * This implementation calls all the spies in turn. 192 192 */ 193 voidoperator()(const Xapian::Document &doc, Xapian::weight wt);193 double operator()(const Xapian::Document &doc, Xapian::weight wt); 194 194 }; 195 195 196 void196 double 197 197 MultipleMatchSpy::operator()(const Xapian::Document &doc, Xapian::weight wt) { 198 198 LOGCALL_VOID(MATCH, "MultipleMatchSpy::operator()", doc << ", " << wt); 199 vector<Xapian::MatchSpy *>::const_iterator i; 200 for (i = spies.begin(); i != spies.end(); ++i) { 201 (**i)(doc, wt); 199 double min_min_wt = DBL_MAX; 200 vector<Xapian::MatchSpy *>::const_iterator i = spies.begin() 201 while (i != spies.end()) { 202 double min_wt = (**i)(doc, wt); 203 if (rare(min_wt == DBL_MAX)) { 204 i = spies.erase(i); 205 continue; 206 } 207 min_min_wt = std::min(min_min_wt, min_wt); 208 ++i; 202 209 } 210 return min_min_wt; 203 211 } 204 212 205 213 //////////////////////////////////// … … 602 610 ++docs_matched; 603 611 if (!calculated_weight) wt = pl->get_weight(); 604 612 if (matchspy) { 605 matchspy->operator()(doc, wt); 613 double matchspy_min_wt = matchspy->operator()(doc, wt); 614 if (matchspy_min_wt == DBL_MAX) { 615 matchspy = NULL; 616 } 606 617 } 607 618 if (wt > greatest_wt) goto new_greatest_weight; 608 619 continue; … … 645 656 new_item.wt = wt; 646 657 calculated_weight = true; 647 658 } 648 matchspy->operator()(doc, wt); 659 double matchspy_min_wt = matchspy->operator()(doc, wt); 660 if (matchspy_min_wt == DBL_MAX) { 661 matchspy = NULL; 662 } 649 663 } 650 664 } 651 665 } -
include/xapian/matchspy.h
68 68 * 69 69 * @param doc The document seen by the match spy. 70 70 * @param wt The weight of the document. 71 * 72 * @return The minimum weight for documents which the matchspy is 73 * interested in. 71 74 */ 72 virtual voidoperator()(const Xapian::Document &doc,73 Xapian::weight wt) = 0;75 virtual double operator()(const Xapian::Document &doc, 76 Xapian::weight wt) = 0; 74 77 75 78 /** Clone the match spy. 76 79 * … … 188 191 /// Total number of documents seen by the match spy. 189 192 Xapian::doccount total; 190 193 194 /// Maximum number of values to check. 195 Xapian::doccount check_max; 196 191 197 /// The values seen so far, together with their frequency. 192 198 std::map<std::string, Xapian::doccount> values; 193 199 194 200 public: 195 201 /// Construct an empty ValueCountMatchSpy. 196 ValueCountMatchSpy() : slot(Xapian::BAD_VALUENO), total(0) {}202 ValueCountMatchSpy() : slot(Xapian::BAD_VALUENO), total(0), check_max(0) {} 197 203 198 /// Construct a MatchSpy which counts the values in a particular slot. 199 ValueCountMatchSpy(Xapian::valueno slot_) 200 : slot(slot_), total(0) { 204 /** Construct a MatchSpy which counts the values in a particular slot. 205 * 206 * @param slot_ The slot number to check. 207 * @param check_max_ The maximum number of values to check in the slot. 208 * 209 * If check_max_ is 0, no limit is places on the number of values to check. 210 */ 211 ValueCountMatchSpy(Xapian::valueno slot_, check_max_=0) 212 : slot(slot_), total(0), check_max(check_max_) { 201 213 } 202 214 203 215 /// Return the values seen in the slot. … … 226 238 * 227 239 * This implementation tallies values for a matching document. 228 240 */ 229 voidoperator()(const Xapian::Document &doc, Xapian::weight wt);241 double operator()(const Xapian::Document &doc, Xapian::weight wt); 230 242 231 243 virtual MatchSpy * clone() const; 232 244 virtual std::string name() const; -
api/matchspy.cc
156 156 } 157 157 } 158 158 159 void 159 double 160 160 ValueCountMatchSpy::operator()(const Document &doc, weight) { 161 161 ++total; 162 162 string val(doc.get_value(slot)); 163 163 if (!val.empty()) ++values[val]; 164 if (check_max != 0 && rare(total >= check_max)) { 165 return DBL_MAX; 166 } 167 return 0.0; 164 168 } 165 169 166 170 void