cos-list.cxx
changeset 7 1928f1a1ee5b
equal deleted inserted replaced
6:f0c87fb62b66 7:1928f1a1ee5b
       
     1 /* cos-search.cxx:
       
     2  *   based on quickstartsearch.cc: Simplest possible searcher
       
     3  *
       
     4  * ----START-LICENCE----
       
     5  * Copyright 1999,2000,2001 BrightStation PLC
       
     6  * Copyright 2003,2004 Olly Betts
       
     7  * Copyright 2011 Stiletto <blasux@blasux.ru>
       
     8  *
       
     9  * This program is free software; you can redistribute it and/or
       
    10  * modify it under the terms of the GNU General Public License as
       
    11  * published by the Free Software Foundation; either version 2 of the
       
    12  * License, or (at your option) any later version.
       
    13  *
       
    14  * This program is distributed in the hope that it will be useful,
       
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    17  * GNU General Public License for more details.
       
    18  *
       
    19  * You should have received a copy of the GNU General Public License
       
    20  * along with this program; if not, write to the Free Software
       
    21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
       
    22  * USA
       
    23  */
       
    24 
       
    25 #include <xapian.h>
       
    26 #include <iostream>
       
    27 #include <cstdlib>
       
    28 #include <algorithm>
       
    29 #include <pcrecpp.h>
       
    30 
       
    31 using namespace std;
       
    32 
       
    33 int main(int argc, char **argv)
       
    34 {
       
    35     // Simplest possible options parsing: we just require two or more
       
    36     // parameters.
       
    37     if (argc < 3) {
       
    38         cout << "usage: " << argv[0] <<
       
    39                 " <path to database> <term>" << endl;
       
    40         exit(1);
       
    41     }
       
    42 
       
    43     // Catch any Xapian::Error exceptions thrown
       
    44     try {
       
    45 	Xapian::Database db(argv[1]);
       
    46         Xapian::Enquire enquire(db);
       
    47         Xapian::QueryParser qp;
       
    48         string qstring = string(argv[2])+":";
       
    49         std::transform(qstring.begin(), qstring.end(), qstring.begin(), ::toupper);
       
    50 
       
    51         for (Xapian::TermIterator ti = db.allterms_begin(qstring);ti!=db.allterms_end(qstring);ti++)
       
    52             cout << *ti << endl;
       
    53     } catch(const Xapian::Error &error) {
       
    54         cerr << "Exception: "  << error.get_msg() << endl;
       
    55     }
       
    56 }