cos-list.cxx
changeset 7 1928f1a1ee5b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cos-list.cxx	Sat Jun 18 16:11:12 2011 +0400
@@ -0,0 +1,56 @@
+/* cos-search.cxx:
+ *   based on quickstartsearch.cc: Simplest possible searcher
+ *
+ * ----START-LICENCE----
+ * Copyright 1999,2000,2001 BrightStation PLC
+ * Copyright 2003,2004 Olly Betts
+ * Copyright 2011 Stiletto <blasux@blasux.ru>
+ *
+ * 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>
+#include <algorithm>
+#include <pcrecpp.h>
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+    // Simplest possible options parsing: we just require two or more
+    // parameters.
+    if (argc < 3) {
+        cout << "usage: " << argv[0] <<
+                " <path to database> <term>" << endl;
+        exit(1);
+    }
+
+    // Catch any Xapian::Error exceptions thrown
+    try {
+	Xapian::Database db(argv[1]);
+        Xapian::Enquire enquire(db);
+        Xapian::QueryParser qp;
+        string qstring = string(argv[2])+":";
+        std::transform(qstring.begin(), qstring.end(), qstring.begin(), ::toupper);
+
+        for (Xapian::TermIterator ti = db.allterms_begin(qstring);ti!=db.allterms_end(qstring);ti++)
+            cout << *ti << endl;
+    } catch(const Xapian::Error &error) {
+        cerr << "Exception: "  << error.get_msg() << endl;
+    }
+}