Debian Codegraph @

ftsadmin

raw
1 #!/usr/bin/perl -Iblib/arch -Iblib/lib -w
2 #!/usr/bin/perl -w
3
4 use strict;
5 use DBI;
6 use DBIx::FullTextSearch;
7 use Getopt::Long;
8
9 my $dummy;
10
11 my $USAGE = <<'EOF';
12 Usage: ftsadmin [ --version | [ datasource [ --create | --list |
13 fts_index_name [ --contains list_of_words |
14 --econtains list_of_expressions ] ] ] ]
15
16 Examples:
17 ftsadmin user/pass@db --list # lists fts_indexes
18 ftsadmin user/pass@db --create index1 --frontend file --backend blob
19 # creates index
20 EOF
21
22 unless (@ARGV) { die $USAGE; }
23
24
25 if ($ARGV[0] eq '--version' or $ARGV[0] eq '-v') {
26 print "This is ftsadmin version $DBIx::FullTextSearch::VERSION.\n";
27 exit;
28 }
29
30
31 unless (@ARGV) { die "Specify the user/password\@database (or just the database) data source.\n"; }
32
33
34 my $datasource = shift;
35 my ($user, $password, $dsn) = ($datasource =~ m!^(?:(.*?)(?:/(.*))?\@)?(.*)$!);
36 my $text_dsn = (defined $user ? $user.'@' : '' ) . $dsn;
37
38 $dsn = 'dbi:mysql:' . $dsn unless $dsn =~ /^dbi:/;
39 my $dbh = DBI->connect($dsn, $user, $password)
40 or die "Error connecting to database: $DBI::errstr\n";
41
42
43
44 unless (@ARGV) { die "Command or DBIx::FullTextSearch index name expected after datasource.\n"; }
45
46 if ($ARGV[0] eq '--list') {
47 my @list = DBIx::FullTextSearch->list_fts_indexes($dbh);
48 for my $name (@list) { print $name, "\n"; }
49 exit;
50 }
51
52 if ($ARGV[0] eq '--create') {
53 $dummy = shift;
54 if (not @ARGV) { die "Name of index to create expected.\n"; }
55 my $create_name = shift;
56
57 my %options = ();
58 GetOptions(\%options,
59 'frontend=s', 'backend=s',
60 'word_id_bits=i', 'doc_id_bits=i', 'count_bits=i',
61 'word_length=i', 'blob_direct_fetch=i', 'data_table=s',
62 'name_length=i', 'position_bits=i', 'filter=s',
63 'splitter=s', 'init_env=s', 'word_id_table=s',
64 'doc_id_table=s', 'table_name=s', 'column_name=s',
65 'column_id_name=s',
66 );
67
68 DBIx::FullTextSearch->create($dbh, $create_name, %options)
69 or die $DBIx::FullTextSearch::errstr, "\n";
70 exit;
71 }
72
73
74 unless (@ARGV) { die "Name of index to work with expected.\n"; }
75
76 my $index_name = shift;
77 my $fts = DBIx::FullTextSearch->open($dbh, $index_name) or die $DBIx::FullTextSearch::errstr, "\n";
78
79
80 unless (@ARGV) { die "Command for index `$index_name' expected.\n"; }
81
82 if ($ARGV[0] eq '--contains') {
83 $dummy = shift;
84 print join "\n", $fts->contains(@ARGV), '';
85 }
86 elsif ($ARGV[0] eq '--econtains') {
87 $dummy = shift;
88 print join "\n", $fts->econtains(@ARGV), '';
89 }
90 elsif ($ARGV[0] eq '--drop') {
91 $fts->drop;
92 }
93 elsif ($ARGV[0] eq '--index') {
94 $dummy = shift;
95 $fts->index_document(@ARGV);
96 }
97 else {
98 die "Command `$ARGV[0]' not recognized.\n";
99 }
100
101 1;
102
103 =head1 NAME
104
105 ftsadmin - command line admin utility for DBIx::FullTextSearch
106
107 =head1 SYNOPSIS
108
109 ftsadmin jez/hes@test --create zvirata --frontend=string
110 ftsadmin jez/hes@test zvirata --index slon 'Slon ma chobot'
111 ftsadmin jez/hes@test zvirata --index krtek 'Krtek ma bodliny'
112 ftsadmin jez/hes@test zvirata --contains bodliny
113
114 =head1 DESCRIPTION
115
116 ftsadmin is a command line utility for listing, creating
117 and dropping of DBIx::FullTextSearch indexes and for indexing new documents and
118 searching for matches. The schematic listing of ftsadmin arguments
119 is:
120
121 ftsadmin --version
122 ftsadmin user/pass@db --list
123 ftsadmin user/pass@db --create index_name [ parameters ]
124 ftsadmin user/pass@db index_name --index doc_name [ content ]
125 ftsadmin user/pass@db index_name --contains list_of_words
126 ftsadmin user/pass@db index_name --econtains list_of_words
127 ftsadmin user/pass@db index_name --drop
128
129 For command --version that return the version information of the
130 underlying DBIx::FullTextSearch module no user or database specification is needed.
131
132 For all other commands you need to specify a way to connect to the
133 database. The general way is user@password/database but you can omit the
134 password or even the username part, thus
135
136 jezek/heslo@test
137 jezek@test
138 test
139
140 are all valid database specification (valid semantically, of course; you
141 should specify one that will elad to access to the database).
142
143 After the database specification, you can either pass commands that do
144 not operate on existing indexes, or add a name of the index and then
145 commands with possible further arguments.
146
147 The command --list lists all available DBIx::FullTextSearch indexes in the
148 database.
149
150 The command --create creates new index. The name of the index is the
151 first mandatory parameter after the --create command, after that you can
152 specify index options. For the list of them and their meaning, please
153 see the DBIx::FullTextSearch(3) man page.
154
155 If you want to work with existing index, you hve to specify the index
156 name as the second parameter, and as third the command.
157
158 To index a document (add new document or update existing document in
159 the index), use the --index command. This is followed by either the
160 document name (file and url frontends) or the name and the content of the
161 document (the default and string frontends).
162
163 Commands --contains and --econtains return list of documents as their
164 counterpart DBIx::FullTextSearch methods do.
165
166 You can drop existing index with --drop command.
167
168 This program is meant as a fast utility that you can use to easily test
169 various storage parameters of the indexes. For production use you'll
170 probably want to write your own Perl code, using the DBIx::FullTextSearch module
171 directly.
172
173 =head1 AUTHOR
174
175 (c) 1999 Jan Pazdziora, [email protected],
176 http://www.fi.muni.cz/~adelton/ at Faculty of Informatics, Masaryk
177 University in Brno, Czech Republic
178
179 All rights reserved. This package is free software; you can
180 redistribute it and/or modify it under the same terms as Perl itself.
181
182 =head1 SEE ALSO
183
184 L<DBIx::FullTextSearch>
185
186 =cut
187