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 " -r, --reconstruct[=PREFIX] reconstruct text for prefix PREFIX\n"
54 " --help display this help and exit\n"
55 " --version output version information and exit\n";
92 main(
int argc,
char **argv)
107 bool reconstruct =
false;
108 string reconstruct_prefix;
114 cerr <<
"Bad docid value '" <<
optarg <<
"'\n";
120 cerr <<
"Bad start position '" <<
optarg <<
"'\n";
126 cerr <<
"Bad end position '" <<
optarg <<
"'\n";
133 reconstruct_prefix =
optarg;
156 cerr <<
"--doc=DOCID option required.\n";
173 const string&
term = *term_it;
175 if (startpos) pos_it.
skip_to(startpos);
177 heap.push_back(
new Pos(
term, pos_it));
184 while (!heap.empty()) {
185 auto tip = heap.front();
187 if (
pos > endpos)
break;
189 switch (
pos - old_pos) {
195 cout <<
'\n' <<
pos <<
'\t';
198 cout <<
"\nGap of " << (
pos - old_pos - 1)
199 <<
" unused positions\n" <<
pos <<
'\t';
202 cout << tip->get_term();
210 heap.resize(heap.size() - 1);
Pos(const string &term_, const Xapian::PositionIterator &p_)
Xapian::PositionIterator p
const string & get_term() const
Xapian::termpos get_pos() const
An indexed database of documents.
PositionIterator positionlist_end(Xapian::docid, std::string_view) const noexcept
End iterator corresponding to positionlist_begin().
std::string reconstruct_text(Xapian::docid did, size_t length=0, std::string_view prefix={}, Xapian::termpos start_pos=0, Xapian::termpos end_pos=0) const
Reconstruct document text.
TermIterator termlist_begin(Xapian::docid did) const
Start iterating the terms in a document.
PositionIterator positionlist_begin(Xapian::docid did, std::string_view term) const
Start iterating positions for a term in a document.
TermIterator termlist_end(Xapian::docid) const noexcept
End iterator corresponding to termlist_begin().
All exceptions thrown by Xapian are subclasses of Xapian::Error.
std::string get_description() const
Return a string describing this object.
Class for iterating over term positions.
void skip_to(Xapian::termpos termpos)
Advance the iterator to term position termpos.
Wrappers to allow GNU getopt to be used cleanly from C++ code.
#define required_argument
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
#define optional_argument
C++ STL heap implementation with extensions.
Functions to assist creating language-idiomatic iterator wrappers.
void pop(_RandomAccessIterator first, _RandomAccessIterator last, _Compare comp)
void replace(_RandomAccessIterator first, _RandomAccessIterator last, _Compare comp)
void make(_RandomAccessIterator first, _RandomAccessIterator last, _Compare comp)
bool iterator_valid(const Xapian::ESetIterator &it)
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Parse signed and unsigned type from string and check for trailing characters.
bool parse_unsigned(const char *p, T &res)
Various handy string-related helpers.
bool operator()(const Pos *a, const Pos *b)
int main(int argc, char **argv)
static const struct option long_opts[]
Public interfaces for the Xapian library.