00001 00004 /* Copyright (C) 2007,2008,2009,2010,2012 Olly Betts 00005 * Copyright (C) 2007,2009 Lemur Consulting Ltd 00006 * Copyright (C) 2010 Richard Boulton 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef XAPIAN_INCLUDED_MATCHSPY_H 00024 #define XAPIAN_INCLUDED_MATCHSPY_H 00025 00026 #include <xapian/base.h> 00027 #include <xapian/enquire.h> 00028 #include <xapian/termiterator.h> 00029 #include <xapian/visibility.h> 00030 00031 #include <string> 00032 #include <map> 00033 #include <set> 00034 #include <string> 00035 #include <vector> 00036 00037 namespace Xapian { 00038 00039 class Document; 00040 class Registry; 00041 00048 class XAPIAN_VISIBILITY_DEFAULT MatchSpy { 00049 private: 00051 void operator=(const MatchSpy &); 00052 00054 MatchSpy(const MatchSpy &); 00055 00056 protected: 00058 MatchSpy() {} 00059 00060 public: 00062 virtual ~MatchSpy(); 00063 00075 virtual void operator()(const Xapian::Document &doc, 00076 Xapian::weight wt) = 0; 00077 00095 virtual MatchSpy * clone() const; 00096 00111 virtual std::string name() const; 00112 00119 virtual std::string serialise() const; 00120 00142 virtual MatchSpy * unserialise(const std::string & s, 00143 const Registry & context) const; 00144 00151 virtual std::string serialise_results() const; 00152 00165 virtual void merge_results(const std::string & s); 00166 00174 virtual std::string get_description() const; 00175 }; 00176 00177 00180 class XAPIAN_VISIBILITY_DEFAULT ValueCountMatchSpy : public MatchSpy { 00181 public: 00182 struct Internal; 00183 00184 #ifndef SWIG // SWIG doesn't need to know about the internal class 00185 struct XAPIAN_VISIBILITY_DEFAULT Internal 00186 : public Xapian::Internal::RefCntBase 00187 { 00189 Xapian::valueno slot; 00190 00192 Xapian::doccount total; 00193 00195 std::map<std::string, Xapian::doccount> values; 00196 00197 Internal() : slot(Xapian::BAD_VALUENO), total(0) {} 00198 Internal(Xapian::valueno slot_) : slot(slot_), total(0) {} 00199 }; 00200 #endif 00201 00202 protected: 00203 Xapian::Internal::RefCntPtr<Internal> internal; 00204 00205 public: 00207 ValueCountMatchSpy() : internal() {} 00208 00210 ValueCountMatchSpy(Xapian::valueno slot_) 00211 : internal(new Internal(slot_)) {} 00212 00214 size_t get_total() const { 00215 return internal->total; 00216 } 00217 00225 TermIterator values_begin() const; 00226 00228 TermIterator values_end() const { 00229 return TermIterator(); 00230 } 00231 00242 TermIterator top_values_begin(size_t maxvalues) const; 00243 00245 TermIterator top_values_end(size_t) const { 00246 return TermIterator(); 00247 } 00248 00256 void operator()(const Xapian::Document &doc, Xapian::weight wt); 00257 00258 virtual MatchSpy * clone() const; 00259 virtual std::string name() const; 00260 virtual std::string serialise() const; 00261 virtual MatchSpy * unserialise(const std::string & s, 00262 const Registry & context) const; 00263 virtual std::string serialise_results() const; 00264 virtual void merge_results(const std::string & s); 00265 virtual std::string get_description() const; 00266 }; 00267 00268 } 00269 00270 #endif // XAPIAN_INCLUDED_MATCHSPY_H