1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
# -*- Mode: Perl -*- |
# -*- Mode: Perl -*- |
3 |
# $Basename$ |
# $Basename$ |
4 |
# $Revision: 1.9 $ |
# $Revision: 1.11 $ |
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 |
my %OPT = ( |
my %OPT = ( |
35 |
database => 'DB', |
database => 'oreilly_de_catalog', |
36 |
dir => $WAIT::Config->{WAIT_home} || '/tmp', |
dir => '/usr/local/apache/data', |
37 |
table => 'ora', |
table => 'ora', |
38 |
); |
); |
39 |
|
|
54 |
my $layout = new WAIT::Parse::Ora; |
my $layout = new WAIT::Parse::Ora; |
55 |
|
|
56 |
use lib "/usr/local/apache/lib"; |
use lib "/usr/local/apache/lib"; |
57 |
use oreilly_de_catalog::wait_handler; |
use oreilly_de_catalog::wait_filter; |
58 |
|
|
59 |
my $stem = ['OR_tr_20020124', 'OR_lc_20020124', 'split2', 'stop', 'Stem']; |
my $stem = ['OR_tr_20020124', 'OR_lc_20020125', 'split2', 'stop', 'Stem']; |
60 |
my $text = [{ |
my $text = ['OR_tr_20020124', 'OR_lc_20020125', 'split2', 'stop']; |
61 |
'prefix' => ['OR_tr_20020124', 'OR_lc_20020124'], |
my $wplus = ['split2', 'OR_lc_20020125', 'OR_mixedonly_20020221']; |
62 |
'intervall' => ['OR_tr_20020124', 'OR_lc_20020124'], |
my $sound = ['OR_tr_20020124', 'OR_lc_20020125', 'split2', 'Soundex']; |
63 |
}, |
my $trigr = ['OR_lc_20020125', 'OR_trigrams_20020125']; |
64 |
'OR_tr_20020124', 'OR_lc_20020124', 'split2', 'stop']; |
# split6 is better than split13 or split10: it allows them to enter |
65 |
my $sound = ['OR_tr_20020124', 'OR_lc_20020124', 'split2', 'Soundex']; |
# shorter sequences when searching. |
|
my $trigr = ['OR_lc_20020124', 'OR_trigrams_20020125']; |
|
66 |
my $isbn = ['split6', 'OR_isbn_20020127']; |
my $isbn = ['split6', 'OR_isbn_20020127']; |
67 |
|
|
68 |
my $cwd = cwd; |
my $cwd = cwd; |
69 |
|
|
70 |
|
my $droot = shift or die "Usage: $0 <options> Document-Rootdirectories"; |
71 |
|
|
72 |
my %D; |
my %D; |
73 |
my $access = tie %D, 'WAIT::Document::Ora', @ARGV, |
my $access = tie %D, 'WAIT::Document::Ora', $droot, |
74 |
or die "Couldn't tie to file: $!\n"; |
or die "Couldn't tie to dir $droot: $!\n"; |
75 |
|
|
76 |
my $tb = $db->create_table(name => $OPT{table}, |
my $tb = $db->create_table(name => $OPT{table}, |
77 |
attr => ['author', 'isbn', 'title', |
attr => ['author', 'isbn', 'title', |
80 |
access => $access, |
access => $access, |
81 |
invindex => |
invindex => |
82 |
[ |
[ |
|
'title' => $text, |
|
|
# 'title' => $stem, |
|
83 |
'aboutauthor' => $text, |
'aboutauthor' => $text, |
84 |
# 'aboutauthor' => $stem, |
'aboutauthor' => $wplus, |
85 |
'desc' => $text, |
'abouttranslator' => $text, |
86 |
|
'abouttranslator' => $wplus, |
87 |
'abstract' => $text, |
'abstract' => $text, |
88 |
|
'abstract' => $wplus, |
89 |
'author' => $text, |
'author' => $text, |
|
# 'author' => $sound, |
|
90 |
'colophon' => $text, |
'colophon' => $text, |
91 |
|
'colophon' => $wplus, |
92 |
|
'desc' => $text, |
93 |
|
'desc' => $wplus, |
94 |
|
'inx' => $text, |
95 |
|
'inx' => $wplus, |
96 |
'isbn' => $isbn, |
'isbn' => $isbn, |
97 |
|
'subtitle' => $text, |
98 |
|
'subtitle' => $wplus, |
99 |
|
'title' => $text, |
100 |
|
'title' => $wplus, |
101 |
|
'title_orig' => $text, |
102 |
|
'title_orig' => $wplus, |
103 |
|
'toc' => $text, |
104 |
|
'toc' => $wplus, |
105 |
|
'translator' => $text, |
106 |
|
'translator' => $wplus, |
107 |
] |
] |
108 |
); |
); |
109 |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
110 |
|
|
111 |
my ($did, $value); |
my ($did, $value); |
112 |
binmode STDOUT, ":utf8"; |
binmode STDOUT, ":utf8"; |
113 |
while (($did, $value) = each %D) { |
my $ALL; |
114 |
|
my $traceALL = 0; # expensive |
115 |
|
my $done = 0; |
116 |
|
my $todo = keys %D; |
117 |
|
my $lasttimeround = my $starttime = time; |
118 |
|
|
119 |
|
DOC: while (($did, $value) = each %D) { |
120 |
my $record = $layout->split($value); |
my $record = $layout->split($value); |
121 |
my $headline = $record->{title}; |
my $headline = $record->{title}; |
122 |
$headline =~ s/\s+/ /sg; |
$headline =~ s/\s+/ /sg; |
123 |
printf "%15s %s\n", $record->{isbn}, substr($headline,0,60); |
# printf "%15s %s\n", $record->{isbn}, substr($headline,0,60); |
124 |
|
printf "%15s %s...\n", $did, substr($headline,0,60); |
125 |
$tb->insert('docid' => $did, |
$tb->insert('docid' => $did, |
126 |
headline => $headline, |
headline => $headline, |
127 |
%{$record}); |
%{$record}); |
128 |
|
$done++; |
129 |
|
my $spenttime = time - $starttime; |
130 |
|
my $averagetime = $spenttime/$done; |
131 |
|
my $left = $todo-$done; |
132 |
|
printf("%2d secs, %3d done, %3d left, %4d s done, %5.1f s avg, %4d s left\n", |
133 |
|
time - $lasttimeround, |
134 |
|
$done, |
135 |
|
$left, |
136 |
|
$spenttime, |
137 |
|
$averagetime, |
138 |
|
$left*$averagetime, |
139 |
|
); |
140 |
|
$lasttimeround = time; |
141 |
|
if ($traceALL) { # costs a lot when reaching the 100th file or so |
142 |
|
$ALL->{$did} = $record; |
143 |
|
open F, ">:utf8", "$OPT{dir}/$OPT{database}-$jobid/debug.dump" or die; |
144 |
|
print F Data::Dumper::Dumper($ALL); |
145 |
|
close F; |
146 |
|
} |
147 |
} |
} |
148 |
|
undef $ALL; |
149 |
$tb->set(top=>1); |
$tb->set(top=>1); |
150 |
|
|
151 |
my $tritb = $db->create_table( |
my $tritb = $db->create_table( |
161 |
my(@idx) = @{$tb->table->{inverted}{$f} || []}; |
my(@idx) = @{$tb->table->{inverted}{$f} || []}; |
162 |
for my $idx (@idx) { |
for my $idx (@idx) { |
163 |
my $name = $idx->name; |
my $name = $idx->name; |
164 |
next if $name =~ /(_|\b)(Stem|Soundex)(\b|_)/; # irrelevant for alternatives |
next if $name =~ /(_|\b)(mixedonly|Stem|Soundex)(\b|_)/; |
165 |
|
# irrelevant for alternatives |
166 |
my @keys = $idx->keys; |
my @keys = $idx->keys; |
167 |
@dict{@keys} = (); |
@dict{@keys} = (); |
168 |
} |
} |
182 |
$tb->close(); |
$tb->close(); |
183 |
$db->close(); |
$db->close(); |
184 |
|
|
185 |
# 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 |
186 |
# database to be accessible with the $OPT{database} name |
# long name "$OPT{database}-$jobid" (e.g. |
187 |
|
# oreilly_de_catalog-2002-01-28_16:12_16467) and we want that database |
188 |
|
# to be accessible with the oreilly_de_catalog name. |
189 |
|
|
190 |
use File::Spec; |
use File::Spec; |
191 |
my $long_dir = "$OPT{database}-$jobid"; |
chdir $OPT{dir} or die; |
192 |
my $want_dir = File::Spec->catdir($OPT{dir}, $OPT{database}); |
my $dir = "$OPT{database}-$jobid"; |
193 |
my $prel_slink = File::Spec->catdir($OPT{dir}, "$OPT{database}-$$"); |
my $slwant = File::Spec->catdir($OPT{dir}, $OPT{database}); |
194 |
unlink $prel_slink; # may fail |
my $sltmp = File::Spec->catdir($OPT{dir}, "$OPT{database}-$$"); |
195 |
symlink $long_dir, $prel_slink or die "Could not symlink $long_dir, $prel_slink: $!"; |
unlink $sltmp; # may fail |
196 |
rename $prel_slink, $want_dir or die "Could not rename $prel_slink, $want_dir: $!"; |
symlink $dir, $sltmp or die "Couldn't symlink $dir, $sltmp: $!"; |
197 |
|
rename $sltmp, $slwant or die "Couldn't rename $sltmp, $slwant: $!"; |
198 |
system("chmod 777 $want_dir/*/read")==0 or die; |
warn "$slwant now points to $dir"; |
199 |
|
system("chmod 777 $slwant/*/read")==0 or die; |
200 |
|
|
201 |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
202 |
|
|