2009-10-13 17:50:20 +02:00
|
|
|
/* xapian-dump: Create a textual dump of a Xapian database.
|
2009-10-13 17:20:36 +02:00
|
|
|
*
|
2009-10-13 16:50:04 +02:00
|
|
|
* Copyright © 2009 Carl Worth
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see http://www.gnu.org/licenses/ .
|
|
|
|
*
|
|
|
|
* Author: Carl Worth <cworth@cworth.org>
|
|
|
|
*/
|
|
|
|
|
2009-10-13 17:50:20 +02:00
|
|
|
/* Currently the dumped data includes:
|
|
|
|
*
|
|
|
|
* All document IDs
|
|
|
|
*
|
|
|
|
* And for each document ID:
|
|
|
|
*
|
|
|
|
* All terms
|
|
|
|
* All values
|
|
|
|
*
|
|
|
|
* Things not yet dumped include:
|
|
|
|
*
|
|
|
|
* Data associated with a document.
|
|
|
|
*/
|
|
|
|
|
2009-10-13 16:50:04 +02:00
|
|
|
#include <cstdlib>
|
2009-10-13 17:20:36 +02:00
|
|
|
#include <iostream>
|
2009-10-13 16:50:04 +02:00
|
|
|
|
|
|
|
#include <xapian.h>
|
|
|
|
|
2009-10-13 17:20:36 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2009-10-13 17:29:59 +02:00
|
|
|
static void
|
2009-10-13 17:50:20 +02:00
|
|
|
print_document_terms (Xapian::Document doc)
|
2009-10-13 17:29:59 +02:00
|
|
|
{
|
|
|
|
Xapian::TermIterator i;
|
|
|
|
|
2009-10-13 17:50:20 +02:00
|
|
|
printf ("Terms:\n");
|
2009-10-13 17:29:59 +02:00
|
|
|
|
2009-10-13 17:50:20 +02:00
|
|
|
for (i = doc.termlist_begin (); i != doc.termlist_end (); i++)
|
2009-10-13 17:29:59 +02:00
|
|
|
cout << "\t" << *i << endl;
|
|
|
|
}
|
|
|
|
|
2009-10-13 17:50:20 +02:00
|
|
|
static void
|
|
|
|
print_document_values (Xapian::Document doc)
|
|
|
|
{
|
|
|
|
Xapian::ValueIterator i;
|
|
|
|
|
|
|
|
printf ("Values:\n");
|
|
|
|
|
|
|
|
for (i = doc.values_begin (); i != doc.values_end (); i++)
|
|
|
|
cout << "\t" << i.get_valueno() << ": " << *i << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_document (Xapian::Database db, Xapian::docid id)
|
|
|
|
{
|
|
|
|
Xapian::Document doc;
|
|
|
|
|
|
|
|
printf ("Document %u:\n", id);
|
|
|
|
|
|
|
|
doc = db.get_document (id);
|
|
|
|
|
|
|
|
print_document_terms (doc);
|
|
|
|
|
|
|
|
print_document_values (doc);
|
|
|
|
}
|
|
|
|
|
2009-10-13 16:50:04 +02:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2009-10-13 17:20:36 +02:00
|
|
|
const char *database_path;
|
|
|
|
|
2009-10-13 16:50:04 +02:00
|
|
|
if (argc < 2) {
|
|
|
|
fprintf (stderr, "Usage: %s <path-to-xapian-database>\n",
|
|
|
|
argv[0]);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2009-10-13 17:20:36 +02:00
|
|
|
database_path = argv[1];
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Xapian::Database db;
|
|
|
|
Xapian::PostingIterator i;
|
|
|
|
Xapian::docid doc_id;
|
|
|
|
|
|
|
|
db = Xapian::Database (database_path);
|
|
|
|
for (i = db.postlist_begin (""); i != db.postlist_end (""); i++) {
|
|
|
|
doc_id = *i;
|
2009-10-13 17:29:59 +02:00
|
|
|
|
|
|
|
print_document (db, doc_id);
|
2009-10-13 17:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (const Xapian::Error &error) {
|
|
|
|
cerr << "A Xapian exception occurred: " << error.get_msg () << endl;
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2009-10-13 16:50:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|