1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
# -*- Mode: Perl -*- |
# -*- Mode: Perl -*- |
3 |
# $Basename$ |
# $Basename$ |
4 |
# $Revision: 1.3 $ |
# $Revision: 1.9 $ |
5 |
# Author : Ulrich Pfeifer |
# Author : Ulrich Pfeifer |
6 |
# Created On : Mon Dec 31 13:57:11 2001 |
# Created On : Mon Dec 31 13:57:11 2001 |
7 |
# Last Modified By: Ulrich Pfeifer |
# Last Modified By: Ulrich Pfeifer |
11 |
# (C) Copyright 2001, UUNET Deutschland GmbH, Germany |
# (C) Copyright 2001, UUNET Deutschland GmbH, Germany |
12 |
# |
# |
13 |
|
|
14 |
|
use 5.007; |
15 |
|
|
16 |
use strict; |
use strict; |
17 |
|
use Devel::Peek qw(Dump); |
18 |
|
|
19 |
use File::Path; |
use File::Path; |
20 |
use DB_File; |
use DB_File; |
21 |
use Getopt::Long; |
use Getopt::Long; |
22 |
use Cwd; |
use Cwd; |
23 |
|
|
24 |
require WAIT::Config; |
BEGIN {require WAIT::Config;} |
25 |
require WAIT::Database; |
use WAIT::Database; |
26 |
require WAIT::Parse::Ora; |
use WAIT::Parse::Ora; |
27 |
require WAIT::Document::Ora; |
use WAIT::Document::Ora; |
28 |
require WAIT::InvertedIndex; |
use WAIT::InvertedIndex; |
29 |
|
|
30 |
|
|
31 |
$DB_BTREE->{'cachesize'} = 200_000 ; |
$DB_BTREE->{'cachesize'} = 200_000 ; |
32 |
|
|
33 |
my %OPT = (clean => 0, |
my %OPT = ( |
34 |
database => 'DB', |
database => 'DB', |
35 |
dir => $WAIT::Config->{WAIT_home} || '/tmp', |
dir => $WAIT::Config->{WAIT_home} || '/tmp', |
36 |
table => 'ora', |
table => 'ora', |
37 |
); |
); |
38 |
|
|
39 |
GetOptions(\%OPT, |
GetOptions(\%OPT, |
|
'clean!', |
|
40 |
'database=s', |
'database=s', |
41 |
'dir=s', |
'dir=s', |
42 |
'table=s', |
'table=s', |
43 |
) || die "Usage: ...\n"; |
) || die "Usage: ...\n"; |
44 |
|
|
45 |
if ($OPT{clean} and -d "$OPT{dir}/$OPT{database}") { |
my @localtime = localtime; |
46 |
my $tmp = WAIT::Database->open(name => $OPT{database}, |
$localtime[5] += 1900; |
47 |
'directory' => $OPT{dir}) |
$localtime[4]++; |
48 |
or die "Could not open table $OPT{table}: $@\n"; |
my $jobid = sprintf "%04s-%02s-%02s_%02s:%02s_%d", @localtime[5,4,3,2,1], $$; |
49 |
my $tbl = $tmp->table(name => $OPT{table}); |
my $db = WAIT::Database->create(name => "$OPT{database}-$jobid", |
50 |
$tbl->drop if $tbl; |
directory => $OPT{dir}) |
51 |
rmtree("$OPT{dir}/$OPT{database}/$OPT{table}", 1, 1) |
or die "Could not create database $OPT{database}: $@\n"; |
|
if -d "$OPT{dir}/$OPT{database}/$OPT{table}"; |
|
|
$tmp->close; |
|
|
} |
|
|
|
|
|
my $db; |
|
|
unless (-d "$OPT{dir}/$OPT{database}") { |
|
|
$db = WAIT::Database->create(name => $OPT{database}, |
|
|
'directory' => $OPT{dir}) |
|
|
or die "Could not open database $OPT{database}: $@\n"; |
|
|
} |
|
|
else { |
|
|
$db = WAIT::Database->open(name => $OPT{database}, |
|
|
'directory' => $OPT{dir}) |
|
|
or die "Could not open table $OPT{table}: $@\n"; |
|
|
} |
|
52 |
|
|
53 |
my $layout = new WAIT::Parse::Ora; |
my $layout = new WAIT::Parse::Ora; |
54 |
|
|
55 |
my $stem = ['isotr', 'isolc', 'split2', 'stop', 'Stem']; |
use lib "/usr/local/apache/lib"; |
56 |
|
use oreilly_de_catalog::wait_handler; |
57 |
|
|
58 |
|
my $stem = ['OR_tr_20020124', 'OR_lc_20020124', 'split2', 'stop', 'Stem']; |
59 |
my $text = [{ |
my $text = [{ |
60 |
'prefix' => ['isotr', 'isolc'], |
'prefix' => ['OR_tr_20020124', 'OR_lc_20020124'], |
61 |
'intervall' => ['isotr', 'isolc'], |
'intervall' => ['OR_tr_20020124', 'OR_lc_20020124'], |
62 |
}, |
}, |
63 |
'isotr', 'isolc', 'split2', 'stop']; |
'OR_tr_20020124', 'OR_lc_20020124', 'split2', 'stop']; |
64 |
my $sound = ['isotr', 'isolc', 'split2', 'Soundex'],; |
my $sound = ['OR_tr_20020124', 'OR_lc_20020124', 'split2', 'Soundex']; |
65 |
|
my $trigr = ['OR_lc_20020124', 'OR_trigrams_20020125']; |
66 |
|
my $isbn = ['split6', 'OR_isbn_20020127']; |
67 |
|
|
68 |
my $cwd = cwd; |
my $cwd = cwd; |
69 |
|
|
78 |
access => $access, |
access => $access, |
79 |
invindex => |
invindex => |
80 |
[ |
[ |
81 |
'title' => $stem, |
'title' => $text, |
82 |
'about' => $stem, |
# 'title' => $stem, |
83 |
'text' => $text, |
'aboutauthor' => $text, |
84 |
|
# 'aboutauthor' => $stem, |
85 |
|
'desc' => $text, |
86 |
|
'abstract' => $text, |
87 |
'author' => $text, |
'author' => $text, |
88 |
'author' => $sound, |
# 'author' => $sound, |
89 |
'isbn' => $text, |
'colophon' => $text, |
90 |
|
'isbn' => $isbn, |
91 |
] |
] |
92 |
); |
); |
93 |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
94 |
|
|
95 |
my ($did, $value); |
my ($did, $value); |
96 |
|
binmode STDOUT, ":utf8"; |
97 |
while (($did, $value) = each %D) { |
while (($did, $value) = each %D) { |
98 |
my $record = $layout->split($value); |
my $record = $layout->split($value); |
99 |
my $headline = $record->{title}; |
my $headline = $record->{title}; |
104 |
%{$record}); |
%{$record}); |
105 |
} |
} |
106 |
$tb->set(top=>1); |
$tb->set(top=>1); |
107 |
|
|
108 |
|
my $tritb = $db->create_table( |
109 |
|
name => "$OPT{table}_fallback", |
110 |
|
attr => [qw(docid headline)], # name |
111 |
|
# "headline" |
112 |
|
# only for |
113 |
|
# sman |
114 |
|
invindex => [ headline => $trigr ], |
115 |
|
); |
116 |
|
my %dict; |
117 |
|
for my $f ($tb->fields) { |
118 |
|
my(@idx) = @{$tb->table->{inverted}{$f} || []}; |
119 |
|
for my $idx (@idx) { |
120 |
|
my $name = $idx->name; |
121 |
|
next if $name =~ /(_|\b)(Stem|Soundex)(\b|_)/; # irrelevant for alternatives |
122 |
|
my @keys = $idx->keys; |
123 |
|
@dict{@keys} = (); |
124 |
|
} |
125 |
|
} |
126 |
|
my @dictkeys = grep s/^p//, keys %dict; |
127 |
|
my $maxdebug = 5; |
128 |
|
for my $headline (@dictkeys) { |
129 |
|
if ($maxdebug && $headline =~ /[^\040-\177]/) { |
130 |
|
Dump $headline; |
131 |
|
$maxdebug--; |
132 |
|
} |
133 |
|
# printf "%s\n", substr($headline,0,60); |
134 |
|
$tritb->insert(docid => $headline, headline => $headline); |
135 |
|
} |
136 |
|
$tritb->set(top=>1); |
137 |
|
$tritb->close; |
138 |
$tb->close(); |
$tb->close(); |
139 |
$db->close(); |
$db->close(); |
140 |
|
|
141 |
|
# Now we have a new database with a very long name and we want that |
142 |
|
# database to be accessible with the $OPT{database} name |
143 |
|
|
144 |
|
use File::Spec; |
145 |
|
my $long_dir = "$OPT{database}-$jobid"; |
146 |
|
my $want_dir = File::Spec->catdir($OPT{dir}, $OPT{database}); |
147 |
|
my $prel_slink = File::Spec->catdir($OPT{dir}, "$OPT{database}-$$"); |
148 |
|
unlink $prel_slink; # may fail |
149 |
|
symlink $long_dir, $prel_slink or die "Could not symlink $long_dir, $prel_slink: $!"; |
150 |
|
rename $prel_slink, $want_dir or die "Could not rename $prel_slink, $want_dir: $!"; |
151 |
|
|
152 |
|
system("chmod 777 $want_dir/*/read")==0 or die; |
153 |
|
|
154 |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
155 |
|
|
156 |
|
|
166 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
167 |
|
|
168 |
B<index_ora> |
B<index_ora> |
|
[B<-clean>] [B<-noclean>] |
|
169 |
[B<-database> I<dbname>] |
[B<-database> I<dbname>] |
170 |
[B<-dir> I<directory>] |
[B<-dir> I<directory>] |
171 |
[B<-table> I<table name>] |
[B<-table> I<table name>] |
177 |
|
|
178 |
=over 5 |
=over 5 |
179 |
|
|
|
=item B<-clean> / B<-noclean> |
|
|
|
|
|
Clean the table before indexing. Default is B<off>. |
|
|
|
|
180 |
=item B<-database> I<dbname> |
=item B<-database> I<dbname> |
181 |
|
|
182 |
Specify database name. Default is F<DB>. |
Specify database name. Default is F<DB>. |