cos-dbupdate.cxx
changeset 0 56281d90869c
child 3 38269b62d856
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cos-dbupdate.cxx	Sat Feb 12 13:45:55 2011 +0300
@@ -0,0 +1,66 @@
+/* quickstartindex.cc: Simplest possible indexer
+ *
+ * ----START-LICENCE----
+ * Copyright 1999,2000,2001 BrightStation PLC
+ * Copyright 2003,2004 Olly Betts
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+
+#include <xapian.h>
+#include <iostream>
+#include <cstdlib>
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+    // Simplest possible options parsing: we just require three or more
+    // parameters.
+    if(argc < 2) {
+        cout << "usage: " << argv[0] <<
+                " <path to database>" << endl;
+        exit(1);
+    }
+
+    // Catch any Xapian::Error exceptions thrown
+    try {
+        // Make the database
+        Xapian::WritableDatabase database(argv[1], Xapian::DB_CREATE_OR_OPEN);
+        while (1) {
+            string fname;
+            getline(cin,fname);
+            if (cin.eof()||fname.empty())
+                break;
+            Xapian::Document newdocument;
+            newdocument.set_data(fname);
+            newdocument.add_posting("FILENAME="+fname, 0);
+            int i=1;
+            while (1) {
+                string term;
+                getline(cin,term);
+                if (cin.eof()||term.empty())
+                    break;
+                cout << "TERM <" << term << ">" << endl;
+                newdocument.add_posting(term, i++);
+            }
+            database.replace_document("FILENAME="+fname,newdocument);
+            cout << "EOFILE <" << fname << ">" << endl;
+        }
+    } catch(const Xapian::Error &error) {
+        cout << "Exception: "  << error.get_msg() << endl;
+    }
+}