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