1 // Index each paragraph of a text file as a Xapian document.
3 // Copyright (c) 2003 James Aylett
4 // Copyright (c) 2004,2006,2007 Olly Betts
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
24 public static void Main(string[] argv
) {
25 if (argv
.Length
!= 1) {
26 Console
.Error
.WriteLine("Usage: SimpleIndex PATH_TO_DATABASE");
31 // Open the database for update, creating a new database if
33 Xapian
.WritableDatabase database
;
34 database
= new Xapian
.WritableDatabase(argv
[0], Xapian
.Xapian
.DB_CREATE_OR_OPEN
);
36 Xapian
.TermGenerator indexer
= new Xapian
.TermGenerator();
37 Xapian
.Stem stemmer
= new Xapian
.Stem("english");
38 indexer
.SetStemmer(stemmer
);
42 string line
= Console
.In
.ReadLine();
44 if (para
== "") break;
50 // We've reached the end of a paragraph, so index it.
51 Xapian
.Document doc
= new Xapian
.Document();
54 indexer
.SetDocument(doc
);
55 indexer
.IndexText(para
);
57 // Add the document to the database.
58 database
.AddDocument(doc
);
62 if (para
!= "") para
+= " ";
66 } catch (Exception e
) {
67 Console
.Error
.WriteLine("Exception: " + e
.ToString());