[ci] Fix clang-santisers job for GHA change
[xapian.git] / xapian-bindings / tcl8 / docs / examples / simplesearch.tcl
blob9738ce4ecd6acbcffb11bdb17828de0695d3839f
1 #!/usr/bin/env tclsh
2 # Simple command-line search Tcl script.
4 # Copyright (C) 2004,2006,2007 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 only actually need Xapian 0.9.3 (for the query from list constructor
22 # wrapper), but "package require" doesn't accept differing major versions.
23 package require xapian 1.0.0
25 if {[llength $argv] < 2} {
26 puts "Usage: $argv0 PATH_TO_DATABASE QUERY"
27 exit 1
30 if {[catch {
31 xapian::Database database [lindex $argv 0]
33 # Start an enquire session.
34 xapian::Enquire enquire database
36 # Combine the rest of the command line arguments with spaces between
37 # them, so that simple queries don't have to be quoted at the shell
38 # level.
39 set query_string [join [lrange $argv 1 end]]
40 xapian::QueryParser qp
41 xapian::Stem stemmer "english"
42 qp set_stemmer stemmer
43 qp set_database database
44 qp set_stemming_strategy $xapian::QueryParser_STEM_SOME
45 set query [qp parse_query $query_string]
46 puts "Parsed query is: [$query get_description]"
48 # Find the top 10 results for the query.
49 enquire set_query $query
50 set matches [enquire get_mset 0 10]
52 # Display the results.
53 puts "[$matches get_matches_estimated] results found:"
55 for {set i [$matches begin]} {![$i equals [$matches end]]} {$i next} {
56 xapian::Document document [$i get_document]
57 set rank [expr [$i get_rank] + 1]
58 puts [format {%s: %s%% docid=%s [%s]} \
59 $rank [$i get_percent] [$i get_docid] [document get_data]]
61 } exception]} {
62 puts stderr "Exception: $errorCode $exception"
63 exit 1