cos-dbupdate.cxx
author Stiletto <blasux@blasux.ru>
Sat, 12 Feb 2011 13:45:55 +0300
changeset 0 56281d90869c
child 3 38269b62d856
permissions -rw-r--r--
Initial commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     1
/* quickstartindex.cc: Simplest possible indexer
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     2
 *
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     3
 * ----START-LICENCE----
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     4
 * Copyright 1999,2000,2001 BrightStation PLC
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     5
 * Copyright 2003,2004 Olly Betts
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     6
 *
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     7
 * This program is free software; you can redistribute it and/or
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     8
 * modify it under the terms of the GNU General Public License as
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     9
 * published by the Free Software Foundation; either version 2 of the
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    10
 * License, or (at your option) any later version.
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    11
 *
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful,
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    15
 * GNU General Public License for more details.
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    16
 *
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    18
 * along with this program; if not, write to the Free Software
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    20
 * USA
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    21
 */
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    22
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    23
#include <xapian.h>
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    24
#include <iostream>
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    25
#include <cstdlib>
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    26
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    27
using namespace std;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    28
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    29
int main(int argc, char **argv)
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    30
{
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    31
    // Simplest possible options parsing: we just require three or more
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    32
    // parameters.
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    33
    if(argc < 2) {
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    34
        cout << "usage: " << argv[0] <<
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    35
                " <path to database>" << endl;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    36
        exit(1);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    37
    }
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    38
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    39
    // Catch any Xapian::Error exceptions thrown
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    40
    try {
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    41
        // Make the database
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    42
        Xapian::WritableDatabase database(argv[1], Xapian::DB_CREATE_OR_OPEN);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    43
        while (1) {
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    44
            string fname;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    45
            getline(cin,fname);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    46
            if (cin.eof()||fname.empty())
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    47
                break;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    48
            Xapian::Document newdocument;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    49
            newdocument.set_data(fname);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    50
            newdocument.add_posting("FILENAME="+fname, 0);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    51
            int i=1;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    52
            while (1) {
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    53
                string term;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    54
                getline(cin,term);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    55
                if (cin.eof()||term.empty())
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    56
                    break;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    57
                cout << "TERM <" << term << ">" << endl;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    58
                newdocument.add_posting(term, i++);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    59
            }
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    60
            database.replace_document("FILENAME="+fname,newdocument);
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    61
            cout << "EOFILE <" << fname << ">" << endl;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    62
        }
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    63
    } catch(const Xapian::Error &error) {
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    64
        cout << "Exception: "  << error.get_msg() << endl;
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    65
    }
56281d90869c Initial commit
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    66
}