/* 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);
string fnameterm = "FILENAME:"+fname;
if (fnameterm.length()>245)
fnameterm.erase(245);
newdocument.add_posting(fnameterm, 0);
int i=1;
while (1) {
string term;
getline(cin,term);
if (cin.eof()||term.empty())
break;
if (term.length()>245)
term.erase(245);
cout << "TERM <" << term << ">" << endl;
newdocument.add_posting(term, i++);
}
database.replace_document(fnameterm,newdocument);
cout << "EOFILE <" << fname << ">" << endl;
}
} catch(const Xapian::Error &error) {
cout << "Exception: " << error.get_msg() << endl;
}
}