# Xapian::TermCountMatchSpy Class Reference

Class for counting the frequencies of terms in the matching documents. More...

`#include <matchspy.h>`

Inheritance diagram for Xapian::TermCountMatchSpy:

[legend]
Collaboration diagram for Xapian::TermCountMatchSpy:

[legend]
List of all members.

## Public Member Functions

| TermCountMatchSpy ()
| Default constructor.
| TermCountMatchSpy (std::string prefix)
| Construct a MatchSpy which counts the terms with a particular prefix.
void | add_prefix (std::string prefix)
| Add a prefix to count terms with.
const std::map< std::string, Xapian::doccount > & | get_terms (std::string prefix) const
| Return the suffixes of those terms seen with prefix prefix.
size_t | get_documents_seen () const
| Return the number of documents tallied.
size_t | get_terms_seen () const
| Return the number of term occurrences tallied.
void | get_top_terms (std::vector< StringAndFrequency > &result, std::string prefix, size_t maxterms) const
| Get the most frequent terms with a given prefix.
bool | operator() (const Xapian::Document &doc) const
| Implementation of virtual operator().

## Protected Attributes

Xapian::doccount | documents_seen
| Total number of documents seen by the match spy.
Xapian::termcount | terms_seen
| Total number of term instances seen by the match spy.
std::map< std::string, std::map< std::string, Xapian::doccount > > | terms
| Set of term suffixes seen for each prefix so far, together with their frequency.

## Detailed Description

Class for counting the frequencies of terms in the matching documents.

Note that accessing the list of terms is generally more expensive than accessing a value, so if it is possible to store the information you need in a value, you should probably use a ValueCountMatchSpy instead of a TermCountMatchSpy.

## Constructor & Destructor Documentation

Xapian::TermCountMatchSpy::TermCountMatchSpy | ( |  | ) | `[inline]`

Default constructor.

Xapian::TermCountMatchSpy::TermCountMatchSpy | ( | std::string | prefix | ) | `[inline]`

Construct a MatchSpy which counts the terms with a particular prefix.

Further prefixes can be added by calling add_prefix().

## Member Function Documentation

void Xapian::TermCountMatchSpy::add_prefix | ( | std::string | prefix | ) | `[inline]`

Add a prefix to count terms with.

A TermCountMatchSpy can count terms with one or more prefixes. If the prefixes overlap (eg, "X" and "XA"), terms with both prefixes will be counted for each of those prefixes.

const std::map<std::string, Xapian::doccount>& Xapian::TermCountMatchSpy::get_terms | ( | std::string | prefix | ) | const`[inline]`

Return the suffixes of those terms seen with prefix prefix.

Parameters:

  | prefix | The prefix to examine (must have specified for examination before performing the match - either by using the add_prefix() method, or using the constructor which takes a prefix.)

size_t Xapian::TermCountMatchSpy::get_documents_seen | ( |  | ) | const`[inline]`

Return the number of documents tallied.

size_t Xapian::TermCountMatchSpy::get_terms_seen | ( |  | ) | const`[inline]`

Return the number of term occurrences tallied.

If terms occur in more than one of the prefixes specified, they will be counted multiple times.

void Xapian::TermCountMatchSpy::get_top_terms | ( | std::vector< StringAndFrequency > & | result,
|  | std::string | prefix,
|  | size_t | maxterms |
| ) |  |  | const

Get the most frequent terms with a given prefix.

Parameters:

  | result | A vector which will be filled with the most frequent terms, in descending order of frequency. Terms with the same frequency will be sorted in ascending alphabetical order.
  | prefix | The prefix to examine (must have specified for examination before performing the match - either by using the add_prefix() method, or using the constructor which takes a prefix.)
  | maxterms | The maximum number of terms to return.

bool Xapian::TermCountMatchSpy::operator() | ( | const Xapian::Document & | doc | ) | const`[virtual]`

Implementation of virtual operator().

This implementation tallies terms for a matching document.

Implements Xapian::MatchDecider.

## Member Data Documentation

Xapian::doccount Xapian::TermCountMatchSpy::documents_seen`[mutable, protected]`

Total number of documents seen by the match spy.

Xapian::termcount Xapian::TermCountMatchSpy::terms_seen`[mutable, protected]`

Total number of term instances seen by the match spy.

std::map<std::string, std::map<std::string, Xapian::doccount> > Xapian::TermCountMatchSpy::terms`[mutable, protected]`

Set of term suffixes seen for each prefix so far, together with their frequency.

Only the suffix (ie, the part of the term after the prefix) is stored, to reduce memory usage.

The documentation for this class was generated from the following file:

- include/xapian/matchspy.h