#!/usr/bin/perl #Example of init new data base use strict; use lib qw (.); use Search::OpenFTS::Index; use DBI(); my $TABLE = 'pages'; if ( $#ARGV < 0 ) { print "Usage:\n$0 DATABASE[:PREFIX]\ncontrib/tsearch2 is required!\n"; print "Drop OpenFTS instance: $0 DATABASE[:PREFIX] [drop]\n"; exit; } my ( $dbname, $PREFIX ) = ''; ( $dbname, $PREFIX ) = split( ':', $ARGV[0] ); my $dbi = DBI->connect( 'DBI:Pg:dbname=' . $dbname ); $dbi || die; if ( $ARGV[1] eq 'drop' ) { my $idx = Search::OpenFTS::Index->new( $dbi, $PREFIX ) || die; $idx->drop; $dbi->do("drop table $idx->{TABLE};") || warn "Can't drop table" . $idx->{TABLE}; $dbi->disconnect; exit; } my $TPREFIX = $PREFIX . "_" if ($PREFIX); my $DICT_UNKNOWN_LEXEM_TABLE = $TPREFIX . 'fts_unknown_lexem'; $dbi->do( "create table ${TPREFIX}$TABLE ( tid int not null primary key, path varchar unique, fts_index tsvector );" ) || die; { my $idx = Search::OpenFTS::Index->init( dbi => $dbi, prefix => $PREFIX, txttid => ${TPREFIX} . $TABLE . '.tid', tsvector_field => 'fts_index', ignore_id_index => [qw( 3 4 5 6 7 8 9 12 13 14 15 18 19 23 )], ignore_headline => [qw(13 15 16 17 5)], map => '{ \'20\'=>[4], 21=>[5], 22=>[5], # numbers 1=>[0,1], 11=>[0,1], 16=>[0,1], # latin 2=>[2,3], 10=>[2,3], 17=>[2,3], # cyrillic 3=>[6], 4=>[6], 5=>[6], 6=>[6], 8=>[6], 18=>[6], 19=>[6], # unknown }', dict => [ # 'Search::OpenFTS::Dict::PorterEng', # 'Dict::EngStem', # example how to use snowball stemmer { mod => 'Search::OpenFTS::Morph::ISpell', param => '{aff_file=>"/usr/local/lib/english.aff",dict_file=>"/usr/local/lib/english.dict",stop_file=>"/u/megera/app/fts/test-suite/Dict/english.stop" }' }, # { mod=>'Search::OpenFTS::Dict::Snowball', param=>'{lang=>"english", stop_file=>"/u/megera/app/fts/test-suite/Dict/english.stop"}' }, { mod => 'Dict::StemSnowball', param => '{lang=>"english", stop_file=>"/u/megera/app/fts/test-suite/Dict/english.stop"}' }, { mod => 'Search::OpenFTS::Morph::ISpell', param => '{aff_file=>"/usr/local/lib/russian.aff",dict_file=>"/usr/local/lib/russian.dict",stop_file=>"/u/megera/app/fts/test-suite/Dict/russian.stop",locale=>"ru_RU.KOI8-R" }' }, # { mod=>'Search::OpenFTS::Dict::Snowball', param=>'{lang=>"russian", stop_file=>"/u/megera/app/fts/test-suite/Dict/russian.stop"}' }, { mod => 'Dict::StemSnowball', param => '{lang=>"russian", stop_file=>"/u/megera/app/fts/test-suite/Dict/russian.stop"}' }, { mod => 'Dict::DecimalDict', param => '{MAXLENFRAC=>2,REJECTLONG=>0}' }, { mod => 'Dict::IntegerDict', param => '{MAXLEN =>6,REJECTLONG=>0}' }, { mod => 'Search::OpenFTS::Dict::UnknownDict', param => "{table => \'$DICT_UNKNOWN_LEXEM_TABLE\'}" }, ] ); die "QQQ: $@" if !$idx; # here we could index files using method $idx->index; # it should be quite fast, because indices doesn't created yet $idx->create_index ; #this function called automatically when destroy object $idx # grant permissions on search tables and indices to PUBLIC my $grant = $idx->fix_permissions(); print "Permissions (select) granted on search tables and indices to PUBLIC\n" if ( $grant == 1 ); } $dbi->disconnect;