2 # Tcl script to index each paragraph of a text file as a Xapian document.
4 # Copyright (C) 2004,2006,2007,2009 Olly Betts
5 # Copyright (C) 2004 Michael Schlenker
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
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.
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 USA
21 # We need at least Xapian 1.0.0 for TermGenerator.
22 package require xapian
1.0.0
24 if {[llength $argv] != 1} {
25 puts "Usage: $argv0 PATH_TO_DATABASE"
30 set dbpath
[lindex $argv 0]
31 xapian
::WritableDatabase database
$dbpath $xapian::DB_CREATE_OR_OPEN
32 xapian
::TermGenerator indexer
33 xapian
::Stem stemmer
"english"
34 indexer set_stemmer stemmer
37 while {![eof stdin
]} {
39 set line
[string trim
$line]
40 if {[string equal
$line ""] && [string compare
$para ""]} {
41 # We've reached the end of a paragraph, so index it.
45 indexer set_document doc
46 indexer index_text
$para
48 # Add the document to the database.
49 database add_document doc
52 if {[string equal
$para ""]} {
55 set para
"$para $line"
59 # We *must* delete the database so that the destructor gets called so
60 # pending changes are committed and the lock file is removed.
63 puts stderr
"Exception: $errorCode $exception"