1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
# -*- Mode: Perl -*- |
# -*- Mode: Perl -*- |
3 |
# $Basename$ |
# $Basename$ |
4 |
# $Revision: 1.8 $ |
# $Revision: 1.12 $ |
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 |
8 |
# Last Modified On: Fri Jan 4 15:59:20 2002 |
# Last Modified On: Fri Jan 4 15:59:20 2002 |
9 |
# Language : CPerl |
# Language : CPerl |
10 |
# |
# |
11 |
# (C) Copyright 2001, UUNET Deutschland GmbH, Germany |
# (C) Copyright 2001, Ulrich Pfeifer |
12 |
# |
# |
13 |
|
|
14 |
use 5.007; |
use 5.007; |
26 |
use WAIT::Parse::Ora; |
use WAIT::Parse::Ora; |
27 |
use WAIT::Document::Ora; |
use WAIT::Document::Ora; |
28 |
use WAIT::InvertedIndex; |
use WAIT::InvertedIndex; |
29 |
|
use Data::Dumper; |
30 |
|
|
31 |
|
|
32 |
$DB_BTREE->{'cachesize'} = 200_000 ; |
$DB_BTREE->{'cachesize'} = 200_000 ; |
33 |
|
|
34 |
|
use lib "/usr/local/apache/lib"; |
35 |
|
use lib "/online/www/sites/ora/catalogsearch/run/lib"; |
36 |
|
use oreilly_de_catalog::config; |
37 |
|
use oreilly_de_catalog::wait_filter; |
38 |
|
|
39 |
my %OPT = ( |
my %OPT = ( |
40 |
database => 'DB', |
database => 'oreilly_de_catalog', |
41 |
dir => $WAIT::Config->{WAIT_home} || '/tmp', |
dir => oreilly_de_catalog::config::WAITDIR, |
42 |
table => 'ora', |
table => 'ora', |
43 |
); |
); |
44 |
|
|
45 |
|
my $droot = oreilly_de_catalog::config::CATALOG; |
46 |
|
|
47 |
GetOptions(\%OPT, |
GetOptions(\%OPT, |
48 |
'database=s', |
'database=s', |
49 |
'dir=s', |
'dir=s', |
60 |
|
|
61 |
my $layout = new WAIT::Parse::Ora; |
my $layout = new WAIT::Parse::Ora; |
62 |
|
|
63 |
use lib "/usr/local/apache/lib"; |
my $stem = ['OR_tr_20020124', 'OR_lc_20020125', 'split2', 'stop', 'Stem']; |
64 |
use oreilly_de_catalog::wait_handler; |
# my $text = ['OR_tr_20020124', 'split2', 'OR_minus_20020311', 'OR_lc_20020125', 'split2', 'stop']; |
65 |
|
my $text = ['OR_tr_20020124', 'split', 'OR_minus_20020311', 'OR_lc_20020125']; |
66 |
my $stem = ['OR_tr_20020124', 'OR_lc_20020124', 'split2', 'stop', 'Stem']; |
my $wplus = ['split', 'OR_lc_20020125', 'OR_mixedonly_20020221']; |
67 |
my $text = [{ |
my $sound = ['OR_tr_20020124', 'OR_lc_20020125', 'split2', 'Soundex']; |
68 |
'prefix' => ['OR_tr_20020124', 'OR_lc_20020124'], |
my $trigr = ['OR_lc_20020125', 'OR_trigrams_20020125']; |
69 |
'intervall' => ['OR_tr_20020124', 'OR_lc_20020124'], |
# split6 is better than split13 or split10: it allows them to enter |
70 |
}, |
# shorter sequences when searching. |
71 |
'OR_tr_20020124', 'OR_lc_20020124', 'split2', 'stop']; |
my $isbn = ['split6', 'OR_isbn_20020127']; |
|
my $sound = ['OR_tr_20020124', 'OR_lc_20020124', 'split2', 'Soundex']; |
|
|
my $trigr = ['OR_lc_20020124', 'OR_trigrams_20020125']; |
|
72 |
|
|
73 |
my $cwd = cwd; |
my $cwd = cwd; |
74 |
|
|
75 |
my %D; |
my %D; |
76 |
my $access = tie %D, 'WAIT::Document::Ora', @ARGV, |
my $access = tie %D, 'WAIT::Document::Ora', $droot, |
77 |
or die "Couldn't tie to file: $!\n"; |
or die "Couldn't tie to dir $droot: $!\n"; |
78 |
|
|
79 |
my $tb = $db->create_table(name => $OPT{table}, |
my $tb = $db->create_table(name => $OPT{table}, |
80 |
attr => ['author', 'isbn', 'title', |
attr => ['author', 'isbn', 'title', |
83 |
access => $access, |
access => $access, |
84 |
invindex => |
invindex => |
85 |
[ |
[ |
86 |
'title' => $stem, |
'aboutauthor' => $text, |
87 |
'about' => $stem, |
'aboutauthor' => $wplus, |
88 |
'text' => $text, |
'abouttranslator' => $text, |
89 |
|
'abouttranslator' => $wplus, |
90 |
|
'abstract' => $text, |
91 |
|
'abstract' => $wplus, |
92 |
'author' => $text, |
'author' => $text, |
93 |
'colophon' => $text, |
'colophon' => $text, |
94 |
'author' => $sound, |
'colophon' => $wplus, |
95 |
'isbn' => $text, |
'desc' => $text, |
96 |
|
'desc' => $wplus, |
97 |
|
'inx' => $text, |
98 |
|
'inx' => $wplus, |
99 |
|
'isbn' => $isbn, |
100 |
|
'subtitle' => $text, |
101 |
|
'subtitle' => $wplus, |
102 |
|
'title' => $text, |
103 |
|
'title' => $wplus, |
104 |
|
'title_orig' => $text, |
105 |
|
'title_orig' => $wplus, |
106 |
|
'toc' => $text, |
107 |
|
'toc' => $wplus, |
108 |
|
'translator' => $text, |
109 |
|
'translator' => $wplus, |
110 |
] |
] |
111 |
); |
); |
112 |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
113 |
|
|
114 |
my ($did, $value); |
my ($did, $value); |
115 |
binmode STDOUT, ":utf8"; |
binmode STDOUT, ":utf8"; |
116 |
while (($did, $value) = each %D) { |
my $ALL; |
117 |
|
my $traceALL = 0; # expensive |
118 |
|
my $done = 0; |
119 |
|
my $todo = keys %D; |
120 |
|
my $lasttimeround = my $starttime = time; |
121 |
|
|
122 |
|
DOC: while (($did, $value) = each %D) { |
123 |
|
# next unless $did eq "jscook"; |
124 |
my $record = $layout->split($value); |
my $record = $layout->split($value); |
125 |
my $headline = $record->{title}; |
my $headline = $record->{title}; |
126 |
$headline =~ s/\s+/ /sg; |
$headline =~ s/\s+/ /sg; |
127 |
printf "%15s %s\n", $record->{isbn}, substr($headline,0,60); |
# printf "%15s %s\n", $record->{isbn}, substr($headline,0,60); |
128 |
|
printf "%15s %s...\n", $did, substr($headline,0,60); |
129 |
$tb->insert('docid' => $did, |
$tb->insert('docid' => $did, |
130 |
headline => $headline, |
headline => $headline, |
131 |
%{$record}); |
%{$record}); |
132 |
|
$done++; |
133 |
|
my $spenttime = time - $starttime; |
134 |
|
my $averagetime = $spenttime/$done; |
135 |
|
my $left = $todo-$done; |
136 |
|
printf("%2d secs, %3d done, %3d left, %4d s done, %5.1f s avg, %4d s left\n", |
137 |
|
time - $lasttimeround, |
138 |
|
$done, |
139 |
|
$left, |
140 |
|
$spenttime, |
141 |
|
$averagetime, |
142 |
|
$left*$averagetime, |
143 |
|
); |
144 |
|
$lasttimeround = time; |
145 |
|
if ($traceALL) { # costs a lot when reaching the 100th file or so |
146 |
|
$ALL->{$did} = $record; |
147 |
|
open F, ">:utf8", "$OPT{dir}/$OPT{database}-$jobid/debug.dump" or die; |
148 |
|
print F Data::Dumper::Dumper($ALL); |
149 |
|
close F or die "Couldn't close debug.dump: $!";; |
150 |
|
} |
151 |
} |
} |
152 |
|
undef $ALL; |
153 |
$tb->set(top=>1); |
$tb->set(top=>1); |
154 |
|
|
155 |
my $tritb = $db->create_table( |
my $tritb = $db->create_table( |
156 |
name => "$OPT{table}_fallback", |
name => "$OPT{table}_fallback", |
157 |
attr => [qw(docid headline)], |
attr => [qw(docid headline)], # name |
158 |
|
# "headline" |
159 |
|
# only for |
160 |
|
# sman |
161 |
invindex => [ headline => $trigr ], |
invindex => [ headline => $trigr ], |
162 |
); |
); |
163 |
my %dict; |
my %dict; |
164 |
for my $f ($tb->fields) { |
for my $f ($tb->fields) { |
165 |
my(@idx) = @{$tb->table->{inverted}{$f} || []}; |
my(@idx) = @{$tb->table->{inverted}{$f} || []}; |
166 |
for my $idx (@idx) { |
for my $idx (@idx) { |
167 |
|
my $name = $idx->name; |
168 |
|
next if $name =~ /(_|\b)(mixedonly|Stem|Soundex)(\b|_)/; |
169 |
|
# irrelevant for alternatives |
170 |
my @keys = $idx->keys; |
my @keys = $idx->keys; |
171 |
@dict{@keys} = (); |
@dict{@keys} = (); |
172 |
} |
} |
178 |
Dump $headline; |
Dump $headline; |
179 |
$maxdebug--; |
$maxdebug--; |
180 |
} |
} |
181 |
|
# printf "%s\n", substr($headline,0,60); |
182 |
$tritb->insert(docid => $headline, headline => $headline); |
$tritb->insert(docid => $headline, headline => $headline); |
183 |
} |
} |
184 |
$tritb->set(top=>1); |
$tritb->set(top=>1); |
185 |
$tritb->close; |
$tritb->close or die "Couldn't close table: $!"; |
186 |
$tb->close(); |
$tb->close() or die "Couldn't close table: $!"; |
187 |
$db->close(); |
$db->close() or die "Couldn't close database: $!"; |
188 |
|
|
189 |
# Now we have a new database with a very long name and we want that |
# Atomically relinking symlink: now we have a new database with a very |
190 |
# database to be accessible with the $OPT{database} name |
# long name "$OPT{database}-$jobid" (e.g. |
191 |
|
# oreilly_de_catalog-2002-01-28_16:12_16467) and we want that database |
192 |
|
# to be accessible with the oreilly_de_catalog name. |
193 |
|
|
194 |
use File::Spec; |
use File::Spec; |
195 |
my $long_dir = "$OPT{database}-$jobid"; |
chdir $OPT{dir} or die; |
196 |
my $want_dir = File::Spec->catdir($OPT{dir}, $OPT{database}); |
my $dir = "$OPT{database}-$jobid"; |
197 |
my $prel_slink = File::Spec->catdir($OPT{dir}, "$OPT{database}-$$"); |
my $slwant = File::Spec->catdir($OPT{dir}, $OPT{database}); |
198 |
unlink $prel_slink; # may fail |
my $sltmp = File::Spec->catdir($OPT{dir}, "$OPT{database}-$$"); |
199 |
symlink $long_dir, $prel_slink or die "Could not symlink $long_dir, $prel_slink: $!"; |
unlink $sltmp; # may fail |
200 |
rename $prel_slink, $want_dir or die "Could not rename $prel_slink, $want_dir: $!"; |
symlink $dir, $sltmp or die "Couldn't symlink $dir, $sltmp: $!"; |
201 |
|
rename $sltmp, $slwant or die "Couldn't rename $sltmp, $slwant: $!"; |
202 |
|
warn "$slwant now points to $dir"; |
203 |
|
system("chmod 777 $slwant/*/read")==0 or die; |
204 |
|
|
205 |
|
opendir DIR, "." or die "Could not opendir .: $!"; |
206 |
|
for my $dirent (readdir DIR) { |
207 |
|
next if $dirent =~ /^\./; |
208 |
|
next unless $dirent =~ /^$OPT{database}(.*)/; |
209 |
|
my $ext = $1 or next; |
210 |
|
next unless -M $dirent > 4; |
211 |
|
warn "removing old index $dirent"; |
212 |
|
File::Path::rmtree($dirent); |
213 |
|
} |
214 |
|
closedir DIR; |
215 |
|
|
216 |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
217 |
|
|