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