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