author | Stiletto <blasux@blasux.ru> |
Sat, 12 Feb 2011 17:03:08 +0300 | |
changeset 6 | f0c87fb62b66 |
parent 4 | 64b70fc4f30e |
permissions | -rw-r--r-- |
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); |
|
6
f0c87fb62b66
example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
4
diff
changeset
|
52 |
string fnameterm = "FILENAME:"+fname; |
f0c87fb62b66
example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
4
diff
changeset
|
53 |
if (fnameterm.length()>245) |
f0c87fb62b66
example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
4
diff
changeset
|
54 |
fnameterm.erase(245); |
f0c87fb62b66
example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
4
diff
changeset
|
55 |
newdocument.add_posting(fnameterm, 0); |
0 | 56 |
int i=1; |
57 |
while (1) { |
|
58 |
string term; |
|
59 |
getline(cin,term); |
|
60 |
if (cin.eof()||term.empty()) |
|
61 |
break; |
|
6
f0c87fb62b66
example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
4
diff
changeset
|
62 |
if (term.length()>245) |
f0c87fb62b66
example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
4
diff
changeset
|
63 |
term.erase(245); |
0 | 64 |
cout << "TERM <" << term << ">" << endl; |
65 |
newdocument.add_posting(term, i++); |
|
66 |
} |
|
6
f0c87fb62b66
example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
4
diff
changeset
|
67 |
database.replace_document(fnameterm,newdocument); |
0 | 68 |
cout << "EOFILE <" << fname << ">" << endl; |
69 |
} |
|
70 |
} catch(const Xapian::Error &error) { |
|
71 |
cout << "Exception: " << error.get_msg() << endl; |
|
72 |
} |
|
73 |
} |