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