]> git.notmuchmail.org Git - notmuch/blobdiff - xapian-dump.cc
xapian-dump: Actually dump document IDs
[notmuch] / xapian-dump.cc
index 6d1fc1be6150863155b52b81123b1c6b905de5ed..0ab5e32c7cb6f4f1810a07ec026e903f0bc38a26 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/* xapian-dump: Dump all document IDs from a Xapian database
+ *
  * Copyright © 2009 Carl Worth
  *
  * This program is free software: you can redistribute it and/or modify
  */
 
 #include <cstdlib>
+#include <iostream>
 
 #include <xapian.h>
 
+using namespace std;
+
 int
 main (int argc, char *argv[])
 {
+    const char *database_path;
+
     if (argc < 2) {
        fprintf (stderr, "Usage: %s <path-to-xapian-database>\n",
                 argv[0]);
        exit (1);
     }
 
+    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;
+           printf ("Found document %u\n", doc_id);
+       }
+
+    } catch (const Xapian::Error &error) {
+       cerr << "A Xapian exception occurred: " << error.get_msg () << endl;
+       exit (1);
+    }
+
     return 0;
 }