4
|
1 |
/* cos-dbupdate.cxx: |
|
2 |
* based on quickstartindex.cc: Simplest possible indexer |
0
|
3 |
* |
|
4 |
* ----START-LICENCE---- |
|
5 |
* Copyright 1999,2000,2001 BrightStation PLC |
|
6 |
* Copyright 2003,2004 Olly Betts |
4
|
7 |
* Copyright 2011 Stiletto <blasux@blasux.ru> |
0
|
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 |
|
|
29 |
using namespace std; |
|
30 |
|
|
31 |
int main(int argc, char **argv) |
|
32 |
{ |
|
33 |
// Simplest possible options parsing: we just require three or more |
|
34 |
// parameters. |
|
35 |
if(argc < 2) { |
|
36 |
cout << "usage: " << argv[0] << |
|
37 |
" <path to database>" << endl; |
|
38 |
exit(1); |
|
39 |
} |
|
40 |
|
|
41 |
// Catch any Xapian::Error exceptions thrown |
|
42 |
try { |
|
43 |
// Make the database |
|
44 |
Xapian::WritableDatabase database(argv[1], Xapian::DB_CREATE_OR_OPEN); |
|
45 |
while (1) { |
|
46 |
string fname; |
|
47 |
getline(cin,fname); |
|
48 |
if (cin.eof()||fname.empty()) |
|
49 |
break; |
|
50 |
Xapian::Document newdocument; |
|
51 |
newdocument.set_data(fname); |
3
|
52 |
newdocument.add_posting("FILENAME:"+fname, 0); |
0
|
53 |
int i=1; |
|
54 |
while (1) { |
|
55 |
string term; |
|
56 |
getline(cin,term); |
|
57 |
if (cin.eof()||term.empty()) |
|
58 |
break; |
|
59 |
cout << "TERM <" << term << ">" << endl; |
|
60 |
newdocument.add_posting(term, i++); |
|
61 |
} |
3
|
62 |
database.replace_document("FILENAME:"+fname,newdocument); |
0
|
63 |
cout << "EOFILE <" << fname << ">" << endl; |
|
64 |
} |
|
65 |
} catch(const Xapian::Error &error) { |
|
66 |
cout << "Exception: " << error.get_msg() << endl; |
|
67 |
} |
|
68 |
} |