root / tags / 1.0.8 / xapian-core / docs / quickstartindex.cc.html

Revision 5881, 3.0 kB (checked in by olly, 4 years ago)

NEWS: Updated.
api/omdatabase.cc,backends/database.cc,bin/omtcpsrv.cc,
common/database.h,docs/,include/xapian/database.h,tests/api_db.cc:
Added constructors to Database and WritableDatabase? which fulfil the
role that the Auto::open() factory functions currently do.
Auto::open() is now deprecated.
api/,backends/inmemory/inmemory_database.cc,
backends/quartz/quartz_database.cc,backends/quartz/quartz_postlist.h,
common/expandweight.h,common/stats.h,include/xapian.h:
#include <xapian.h> no longer pulls in xapian/output.h - this
removes the external ability to write a Xapian object to an
ostream directly, as it's little used and potentially dangerous
('cout << mset[i];' will compile, but you almost certainly meant
'cout << *mset[i];'). You can get the old effect by writing
'cout << obj->get_description();' instead of 'cout << obj;'.
Adjusted all the library sources which relied on xapian/output.h
pulling in various other xapian/ headers.
backends/muscat36/da_database.cc,backends/muscat36/db_database.cc:
Debug output tweaks.
common/emptypostlist.h,matcher/mergepostlist.cc,matcher/multimatch.cc:
Added EmptyPostList::get_maxweight() which always returns 0, so you
no longer need to explicitly set a weighting scheme on an
EmptyPostList?.
common/omdebug.h: Only include omstringstream.h if
XAPIAN_DEBUG_VERBOSE is in effect.
extra/Makefile.am: queryparsertest needs to link to libxapian.la
explicitly.
net/progclient.cc: Whitespace tweak.
testsuite/: Eliminated barely used sources indexer.h,
textfile_indexer.h, and textfile_indexer.cc.
testsuite/backendmanager.cc: Removed unused functions
make_strvec() and index_file_to_database().

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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>&lt;xapian.h&gt;</FONT>
31<FONT color=#a020f0>#include </FONT><FONT color=#ff00ff>&lt;iostream&gt;</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 &lt; <FONT color=#ff00ff>4</FONT>) {
39        cout &lt;&lt; <FONT color=#ff00ff>&quot;usage: &quot;</FONT> &lt;&lt; argv[<FONT color=#ff00ff>0</FONT>] &lt;&lt;
40                <FONT color=#ff00ff>&quot; &lt;path to database&gt; &lt;document data&gt; &lt;document terms&gt;&quot;</FONT> &lt;&lt; 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 &lt; 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 &amp;error) {
63        cout &lt;&lt; <FONT color=#ff00ff>&quot;Exception: &quot;</FONT>  &lt;&lt; error.get_msg() &lt;&lt; endl;
64    }
65}
66</PRE>
67</BODY>
68</HTML>
Note: See TracBrowser for help on using the browser.