48 MatchSpy::~MatchSpy() {}
51 MatchSpy::clone()
const {
52 throw UnimplementedError(
"MatchSpy not suitable for use with remote searches - clone() method unimplemented");
57 throw UnimplementedError(
"MatchSpy not suitable for use with remote searches - name() method unimplemented");
61 MatchSpy::serialise()
const {
62 throw UnimplementedError(
"MatchSpy not suitable for use with remote searches - serialise() method unimplemented");
66 MatchSpy::unserialise(
const string &,
const Registry &)
const {
67 throw UnimplementedError(
"MatchSpy not suitable for use with remote searches - unserialise() method unimplemented");
71 MatchSpy::serialise_results()
const {
72 throw UnimplementedError(
"MatchSpy not suitable for use with remote searches - serialise_results() method unimplemented");
76 MatchSpy::merge_results(
const string &) {
77 throw UnimplementedError(
"MatchSpy not suitable for use with remote searches - merge_results() method unimplemented");
81 MatchSpy::get_description()
const {
82 return "Xapian::MatchSpy()";
93 map<string, Xapian::doccount>::const_iterator
it;
128 while (it != spy->
values.end() && it->first < term) {
137 return it == spy->
values.end();
157 : str(str_), frequency(frequency_) {}
189 vector<StringAndFrequency>::const_iterator
it;
205 return it->get_string();
211 return it->get_frequency();
225 while (it != values.end() && it->get_string() < term) {
234 return it == values.end();
263 const map<string, doccount> & items,
267 result.reserve(maxitems);
271 for (map<string, doccount>::const_iterator i = items.begin();
272 i != items.end(); ++i) {
273 Assert(result.size() <= maxitems);
275 if (result.size() > maxitems) {
279 push_heap(result.begin(), result.end(), cmpfn);
282 make_heap(result.begin(), result.end(), cmpfn);
285 pop_heap(result.begin(), result.end(), cmpfn);
291 sort_heap(result.begin(), result.end(), cmpfn);
293 sort(result.begin(), result.end(), cmpfn);
298 ValueCountMatchSpy::operator()(
const Document &doc,
double) {
301 string val(doc.
get_value(internal->slot));
302 if (!val.empty()) ++(internal->values[val]);
306 ValueCountMatchSpy::values_begin()
const 313 ValueCountMatchSpy::top_values_begin(
size_t maxvalues)
const 323 ValueCountMatchSpy::clone()
const {
330 return "Xapian::ValueCountMatchSpy";
334 ValueCountMatchSpy::serialise()
const {
342 ValueCountMatchSpy::unserialise(
const string & s,
const Registry &)
const 344 const char * p = s.data();
345 const char * end = p + s.size();
350 throw NetworkError(
"Junk at end of serialised ValueCountMatchSpy");
357 ValueCountMatchSpy::serialise_results()
const {
358 LOGCALL(REMOTE,
string,
"ValueCountMatchSpy::serialise_results", NO_ARGS);
363 for (map<string, doccount>::const_iterator i = internal->values.begin();
364 i !=
internal->values.end(); ++i) {
373 ValueCountMatchSpy::merge_results(
const string & s) {
374 LOGCALL_VOID(REMOTE,
"ValueCountMatchSpy::merge_results", s);
376 const char * p = s.data();
377 const char * end = p + s.size();
381 internal->total += n;
383 map<string, doccount>::size_type items;
388 string val(p, vallen);
392 internal->values[val] += freq;
396 throw NetworkError(
"Junk at end of serialised ValueCountMatchSpy " 402 ValueCountMatchSpy::get_description()
const {
403 string d =
"ValueCountMatchSpy(";
404 if (
internal.
get()) {
405 d +=
str(internal->total);
406 d +=
" docs seen, looking in ";
407 d +=
str(internal->values.size());
The Xapian namespace contains public interfaces for the Xapian library.
Define the XAPIAN_NORETURN macro.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
A termlist iterator over a vector of StringAndFrequency objects.
length encoded as a string
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
TermList * skip_to(const string &term)
Skip forward to the specified term.
string get_termname() const
Return the termname at the current position.
Xapian::PositionIterator positionlist_begin() const
Return a PositionIterator for the current position.
Xapian::doccount get_frequency() const
Return the frequency.
InvalidOperationError indicates the API was used in an invalid way.
A string with a corresponding frequency.
Abstract base class for match spies.
A termlist iterator over the contents of a ValueCountMatchSpy.
ValueCountTermList(ValueCountMatchSpy::Internal *spy_)
intrusive_ptr< Xapian::ValueCountMatchSpy::Internal > spy
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Abstract base class for termlists.
Convert types to std::string.
std::string get_string() const
Return the string.
std::string encode_length(T len)
Encode a length as a variable-length string.
static void unsupported_method()
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
Hierarchy of classes which Xapian can throw as exceptions.
Class for iterating over a list of terms.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
string get_termname() const
Return the termname at the current position.
map< string, Xapian::doccount >::const_iterator it
bool operator()(const StringAndFrequency &a, const StringAndFrequency &b) const
Return true if a has a higher frequency than b.
std::map< std::string, Xapian::doccount > values
The values seen so far, together with their frequency.
Registry for user subclasses.
vector< StringAndFrequency >::const_iterator it
string str(int value)
Convert int to std::string.
Xapian::PositionIterator positionlist_begin() const
Return a PositionIterator for the current position.
StringAndFrequency(const std::string &str_, Xapian::doccount frequency_)
Construct a StringAndFrequency object.
TermList * next()
Advance the current position to the next term in the termlist.
Xapian::doccount frequency
Class for iterating over term positions.
bool at_end() const
Return true if the current position is past the last term in this list.
static void get_most_frequent_items(vector< StringAndFrequency > &result, const map< string, doccount > &items, size_t maxitems)
Get the most frequent items from a map from string to frequency.
StringAndFreqCmpByFreq()
Default constructor.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Class for counting the frequencies of values in the matching documents.
bool at_end() const
Return true if the current position is past the last term in this list.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
void decode_length_and_check(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Indicates a problem communicating with a remote database.
unsigned valueno
The number for a value slot in a document.
Various handy helpers which std::string really should provide.
Abstract base class for termlists.
void init()
init should be called after the values have been set, but before iteration begins.
TermList * skip_to(const string &term)
Skip forward to the specified term.
Various assertion macros.
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
API for working with documents.
A smart pointer that uses intrusive reference counting.
TermList * next()
Advance the current position to the next term in the termlist.
std::string get_value(Xapian::valueno slot) const
Get value by number.
void decode_length(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
A handle representing a document in a Xapian database.
Compare two StringAndFrequency objects.
Wrapper around standard unique_ptr template.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
UnimplementedError indicates an attempt to use an unimplemented feature.
Class for looking up user subclasses during unserialisation.
vector< StringAndFrequency > values
parsing a user query string to build a Xapian::Query object