39 #define PROG_NAME "xapian-pos" 40 #define PROG_DESC "Debug positional data in a Xapian database" 48 cout <<
"Usage: " PROG_NAME " [OPTIONS] DATABASE\n\n" 50 " -d, --doc=DOCID show positions for document DOCID\n" 51 " -s, --start=POS specifies the first position to show\n" 52 " -e, --end=POS specifies the last position to show\n" 53 " --help display this help and exit\n" 54 " --version output version information and exit\n";
66 : p(p_), term(term_) { pos = *p; }
70 const string&
get_term()
const {
return term; }
95 auto v = strtoull(s, &e, 0);
100 }
else if (v > numeric_limits<T>::max()) {
114 static const struct option long_opts[] = {
127 while ((c =
gnu_getopt_long(argc, argv,
"d:e:s:", long_opts, 0)) != -1) {
131 if (errno == 0) errno = ERANGE;
132 cerr <<
"Bad docid value '" <<
optarg <<
"': " 133 << strerror(errno) <<
'\n';
139 cerr <<
"Bad start position '" <<
optarg <<
"': " 140 << strerror(errno) <<
'\n';
146 cerr <<
"Bad end position '" <<
optarg <<
"': " 147 << strerror(errno) <<
'\n';
171 cerr <<
"--doc=DOCID option required.\n";
181 const string& term = *term_it;
183 if (startpos) pos_it.
skip_to(startpos);
185 heap.push_back(
new Pos(term, pos_it));
189 make_heap(heap.begin(), heap.end(),
PosCmp());
192 while (!heap.empty()) {
193 auto tip = heap.front();
195 if (pos > endpos)
break;
197 switch (pos - old_pos) {
203 cout <<
'\n' << pos <<
'\t';
206 cout <<
"\nGap of " << (pos - old_pos - 1)
207 <<
" unused positions\n" << pos <<
'\t';
210 cout << tip->get_term();
215 pop_heap(heap.begin(), heap.end(),
PosCmp());
216 push_heap(heap.begin(), heap.end(),
PosCmp());
218 pop_heap(heap.begin(), heap.end(),
PosCmp());
219 heap.resize(heap.size() - 1);
PositionIterator positionlist_end(Xapian::docid, const std::string &) const
Corresponding end iterator to positionlist_begin().
Wrappers to allow GNU getopt to be used cleanly from C++ code.
TermIterator termlist_begin(Xapian::docid did) const
An iterator pointing to the start of the termlist for a given document.
int main(int argc, char **argv)
void skip_to(Xapian::termpos termpos)
Advance the iterator to term position termpos.
This class is used to access a database, or a group of databases.
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
bool to_unsigned_int(const char *s, T &result)
PositionIterator positionlist_begin(Xapian::docid did, const std::string &tname) const
An iterator pointing to the start of the position list for a given term in a given document...
Xapian::termpos get_pos() const
Xapian::PositionIterator p
Public interfaces for the Xapian library.
bool iterator_valid(const Xapian::ESetIterator &it)
bool operator()(const Pos *a, const Pos *b)
Class for iterating over term positions.
#define required_argument
TermIterator termlist_end(Xapian::docid) const
Corresponding end iterator to termlist_begin().
std::string get_description() const
Return a string describing this object.
Pos(const string &term_, const Xapian::PositionIterator &p_)
All exceptions thrown by Xapian are subclasses of Xapian::Error.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Various handy helpers which std::string really should provide.
Functions to assist creating language-idiomatic iterator wrappers.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
const string & get_term() const