Ticket #199: matchspy_changes_13246_13247.patch
File matchspy_changes_13246_13247.patch, 16.5 KB (added by , 15 years ago) |
---|
-
xapian-core/tests/api_nodb.cc
Property changes on: xapian-applications/omega/freemem.cc ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-applications/omega/docs/quickstart.rst ___________________________________________________________________ Deleted: svn:keywords - Author Date Id Revision Deleted: svn:eol-style - native Property changes on: xapian-applications/omega/docs/scriptindex.rst ___________________________________________________________________ Deleted: svn:keywords - Author Date Id Revision Deleted: svn:eol-style - native Property changes on: xapian-applications/omega/docs/omegascript.rst ___________________________________________________________________ Deleted: svn:keywords - Author Date Id Revision Deleted: svn:eol-style - native Property changes on: xapian-applications/omega/docs/termprefixes.rst ___________________________________________________________________ Deleted: svn:keywords - Author Date Id Revision Deleted: svn:eol-style - native Property changes on: xapian-applications/omega/docs/cgiparams.rst ___________________________________________________________________ Deleted: svn:keywords - Author Date Id Revision Deleted: svn:eol-style - native Property changes on: xapian-applications/omega/docs/overview.rst ___________________________________________________________________ Deleted: svn:keywords - Author Date Id Revision Deleted: svn:eol-style - native Property changes on: xapian-applications/omega/docs ___________________________________________________________________ Deleted: svn:ignore - .*.sw? Makefile Makefile.in cgiparams.html omegascript.html overview.html quickstart.html scriptindex.html termprefixes.html Property changes on: xapian-applications/omega/freemem.h ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/matcher/collapser.h ___________________________________________________________________ Deleted: svn:mergeinfo Property changes on: xapian-core/docs/doxygen_source.conf.in ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk/xapian-core/docs/doxygen_source.conf.in:r13224-13246 Property changes on: xapian-core/docs/doxygen_source_footer.html_tmpl ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk/xapian-core/docs/doxygen_source_footer.html_tmpl:r13224-13246 Property changes on: xapian-core/docs/doxygen_api.conf.in ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk/xapian-core/docs/doxygen_api.conf.in:r13224-13246 Property changes on: xapian-core/docs/doxygen_source_header.html_tmpl ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk/xapian-core/docs/doxygen_source_header.html_tmpl:r13224-13246
377 377 return true; 378 378 } 379 379 380 // tests the string list serialisation classes. 381 DEFINE_TESTCASE(stringlistserialise1, !backend) 382 { 383 Xapian::StringListSerialiser s1; 384 s1.append("foo"); 385 s1.append(""); 386 Xapian::StringListSerialiser s2(s1); 387 s2.append("baz"); 388 Xapian::StringListUnserialiser p(s2.get()); 389 Xapian::StringListUnserialiser end; 390 TEST(p != end); 391 TEST_EQUAL(*p, "foo"); 392 ++p; 393 TEST(p != end); 394 TEST_EQUAL(*p, ""); 395 p++; 396 TEST(p != end); 397 TEST_EQUAL(*p, "baz"); 398 ++p; 399 TEST(p == end); 400 return true; 401 } 402 380 403 // Test a scaleweight query applied to a match nothing query 381 404 DEFINE_TESTCASE(scaleweight3, !backend) { 382 405 Xapian::Query matchnothing(Xapian::Query::MatchNothing); -
xapian-core/include/xapian/matchspy.h
Property changes on: xapian-core/tests/api_sorting.cc ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/api_postingsource.cc ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk/xapian-core/tests/api_postingsource.cc:r12665-13029,13031-13246 Property changes on: xapian-core/tests/harness/backendmanager_multi.cc ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_remotetcp.cc ___________________________________________________________________ Deleted: svn:keywords - Author Date Id Revision Property changes on: xapian-core/tests/harness/backendmanager_flint.cc ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_remoteprog.cc ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_remoteprog.h ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_multi.h ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_local.h ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_inmemory.cc ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_inmemory.h ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_remotetcp.h ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/tests/harness/backendmanager_flint.h ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/include/xapian/sorter.h ___________________________________________________________________ Added: svn:eol-style + native
157 157 }; 158 158 159 159 160 /// Class to serialise a list of strings in a form suitable for 161 /// ValueCountMatchSpy. 162 class XAPIAN_VISIBILITY_DEFAULT StringListSerialiser { 163 private: 164 std::string serialised; 165 166 public: 167 /// Default constructor. 168 StringListSerialiser() { } 169 170 /// Initialise with a string. 171 /// (The string represents a serialised form, rather than a single value to 172 /// be serialised.) 173 StringListSerialiser(const std::string & initial) : serialised(initial) { } 174 175 /// Initialise from a pair of iterators. 176 template <class Iterator> 177 StringListSerialiser(Iterator begin, Iterator end) : serialised() { 178 while (begin != end) append(*begin++); 179 } 180 181 /// Add a string to the end of the list. 182 void append(const std::string & value); 183 184 /// Get the serialised result. 185 const std::string & get() const { return serialised; } 186 }; 187 188 189 /// Class to unserialise a list of strings serialised by a StringListSerialiser. 190 /// The class can be used as an iterator: use the default constructor to get 191 /// an end iterator. 192 class XAPIAN_VISIBILITY_DEFAULT StringListUnserialiser { 193 private: 194 std::string serialised; 195 std::string curritem; 196 const char * pos; 197 198 /// Read the next item from the serialised form. 199 void read_next(); 200 201 /// Compare this iterator with another 202 friend bool operator==(const StringListUnserialiser & a, 203 const StringListUnserialiser & b); 204 friend bool operator!=(const StringListUnserialiser & a, 205 const StringListUnserialiser & b); 206 207 public: 208 /// Default constructor - use this to define an end iterator. 209 StringListUnserialiser() : pos(NULL) {} 210 211 /// Constructor which takes a serialised list of strings, and creates an 212 /// iterator pointing to the first of them. 213 StringListUnserialiser(const std::string & in) 214 : serialised(in), 215 pos(serialised.data()) 216 { 217 read_next(); 218 } 219 220 /// Copy constructor 221 StringListUnserialiser(const StringListUnserialiser & other) 222 : serialised(other.serialised), 223 curritem(other.curritem), 224 pos((other.pos == NULL) ? NULL : serialised.data() + (other.pos - other.serialised.data())) 225 {} 226 227 /// Assignment operator 228 void operator=(const StringListUnserialiser & other) { 229 serialised = other.serialised; 230 curritem = other.curritem; 231 pos = (other.pos == NULL) ? NULL : serialised.data() + (other.pos - other.serialised.data()); 232 } 233 234 /// Get the current item 235 std::string operator *() const { 236 return curritem; 237 } 238 239 /// Move to the next item. 240 StringListUnserialiser & operator++() { 241 read_next(); 242 return *this; 243 } 244 245 /// Move to the next item (postfix). 246 StringListUnserialiser operator++(int) { 247 StringListUnserialiser tmp = *this; 248 read_next(); 249 return tmp; 250 } 251 252 // Allow use as an STL iterator 253 typedef std::input_iterator_tag iterator_category; 254 typedef std::string value_type; 255 typedef size_t difference_type; 256 typedef std::string * pointer; 257 typedef std::string & reference; 258 }; 259 260 inline bool operator==(const StringListUnserialiser & a, 261 const StringListUnserialiser & b) { 262 return (a.pos == b.pos); 263 } 264 265 inline bool operator!=(const StringListUnserialiser & a, 266 const StringListUnserialiser & b) { 267 return (a.pos != b.pos); 268 } 269 270 160 271 /** A string with a corresponding frequency. 161 272 */ 162 273 class XAPIAN_VISIBILITY_DEFAULT StringAndFrequency { … … 234 345 }; 235 346 236 347 348 /// Class for counting the frequencies of values in the matching documents. 349 class XAPIAN_VISIBILITY_DEFAULT MultiValueCountMatchSpy : public ValueCountMatchSpy { 350 public: 351 /// Construct an empty MultiValueCountMatchSpy. 352 MultiValueCountMatchSpy() {} 353 354 /** Construct a MatchSpy which counts the values in a particular slot. 355 * 356 * Further slots can be added by calling @a add_slot(). 357 */ 358 MultiValueCountMatchSpy(Xapian::valueno slot_) 359 : ValueCountMatchSpy(slot_) { 360 } 361 362 /** Implementation of virtual operator(). 363 * 364 * This implementation tallies values for a matching document. 365 */ 366 void operator()(const Xapian::Document &doc, Xapian::weight wt); 367 368 virtual MatchSpy * clone() const; 369 virtual std::string name() const; 370 virtual std::string serialise() const; 371 virtual MatchSpy * unserialise(const std::string & s, 372 const SerialisationContext & context) const; 373 virtual std::string get_description() const; 374 }; 375 376 237 377 /** A numeric range. 238 378 * 239 379 * This is used to represent ranges of values returned by the match spies. -
xapian-core/api/matchspy.cc
Property changes on: xapian-core/include/xapian/matchspy.h ___________________________________________________________________ Deleted: svn:eol-style - native Property changes on: xapian-core/common/stringutils.cc ___________________________________________________________________ Added: svn:eol-style + native Property changes on: xapian-core/m4-macros/xapian-1.1.m4 ___________________________________________________________________ Deleted: svn:mergeinfo Property changes on: xapian-core/api/sorter.cc ___________________________________________________________________ Added: svn:eol-style + native
84 84 } 85 85 86 86 87 void 88 StringListSerialiser::append(const string & value) 89 { 90 serialised.append(encode_length(value.size())); 91 serialised.append(value); 92 } 93 94 void 95 StringListUnserialiser::read_next() 96 { 97 if (pos == NULL) { 98 return; 99 } 100 if (pos == serialised.data() + serialised.size()) { 101 pos = NULL; 102 curritem.resize(0); 103 return; 104 } 105 106 // FIXME - decode_length will throw a NetworkError if the length is too 107 // long - should be a more appropriate error. 108 size_t currlen = decode_length(&pos, serialised.data() + serialised.size(), true); 109 curritem.assign(pos, currlen); 110 pos += currlen; 111 } 112 113 87 114 /** Compare two StringAndFrequency objects. 88 115 * 89 116 * The comparison is firstly by frequency (higher is better), then by string … … 245 272 } 246 273 247 274 275 void 276 MultiValueCountMatchSpy::operator()(const Document &doc, weight) { 277 ++total; 278 StringListUnserialiser i(doc.get_value(slot)); 279 StringListUnserialiser end; 280 for (; i != end; ++i) { 281 string val(*i); 282 if (!val.empty()) ++values[val]; 283 } 284 } 285 286 MatchSpy * 287 MultiValueCountMatchSpy::clone() const { 288 return new MultiValueCountMatchSpy(slot); 289 } 290 291 string 292 MultiValueCountMatchSpy::name() const { 293 return "Xapian::MultiValueCountMatchSpy"; 294 } 295 296 string 297 MultiValueCountMatchSpy::serialise() const { 298 string result; 299 result += encode_length(slot); 300 return result; 301 } 302 303 MatchSpy * 304 MultiValueCountMatchSpy::unserialise(const string & s, 305 const SerialisationContext &) const{ 306 const char * p = s.data(); 307 const char * end = p + s.size(); 308 309 valueno new_slot = decode_length(&p, end, false); 310 if (p != end) { 311 throw NetworkError("Junk at end of serialised MultiValueCountMatchSpy"); 312 } 313 314 return new MultiValueCountMatchSpy(new_slot); 315 } 316 317 string 318 MultiValueCountMatchSpy::get_description() const { 319 return "Xapian::MultiValueCountMatchSpy(" + str(total) + 320 " docs seen, looking in " + str(values.size()) + " slots)"; 321 } 322 323 248 324 inline double sqrd(double x) { return x * x; } 249 325 250 326 /** Calculate a score based on how evenly distributed the frequencies of a set -
xapian-bindings/python/util.i
Property changes on: xapian-bindings/python/doxy2swig.py ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk/xapian-bindings/python/doxy2swig.py:r13224-13246 Property changes on: xapian-bindings/python/generate-python-exceptions ___________________________________________________________________ Deleted: svn:mergeinfo
396 396 } 397 397 } 398 398 399 %extend StringListUnserialiser { 400 bool __eq__(const StringListUnserialiser &other) { 401 return (*self)==other; 402 } 403 bool __ne__(const StringListUnserialiser &other) { 404 return (*self)!=other; 405 } 406 } 407 399 408 %extend MSet { 400 409 %immutable; 401 410 // access to the items array -
xapian-bindings/xapian.i
473 473 %warnfilter(842) Xapian::TradWeight::unserialise; 474 474 %include <xapian/weight.h> 475 475 476 %ignore Xapian::StringListUnserialiser::operator=; 477 %ignore Xapian::StringListUnserialiser::operator++; 478 %ignore operator==(const StringListUnserialiser &, const StringListUnserialiser &); 479 %ignore operator!=(const StringListUnserialiser &, const StringListUnserialiser &); 480 %extend Xapian::StringListUnserialiser { 481 std::string get() const { 482 return *(*self); 483 } 484 NEXT(std::string, StringListUnserialiser) 485 bool equals(const StringListUnserialiser &other) const { 486 return (*self) == other; 487 } 488 } 489 476 490 %ignore Xapian::NumericRange::operator<; 477 491 %include <xapian/matchspy.h> 478 492