cos-dbupdate.cxx
author Stiletto <blasux@blasux.ru>
Sat, 12 Feb 2011 15:16:11 +0300
changeset 4 64b70fc4f30e
parent 3 38269b62d856
child 6 f0c87fb62b66
permissions -rw-r--r--
header fixes

/* cos-dbupdate.cxx:
 *   based on quickstartindex.cc: Simplest possible indexer
 *
 * ----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>

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;
    }
}