1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
# -*- Mode: Perl -*- |
# -*- Mode: Perl -*- |
3 |
# $Basename$ |
# $Basename$ |
4 |
# $Revision: 1.4 $ |
# $Revision: 1.10 $ |
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; |
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 => 'oreilly_de_catalog', |
35 |
dir => $WAIT::Config->{WAIT_home} || '/tmp', |
dir => '/usr/local/apache/data', |
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 $wplus = ['split2', 'OR_lc_20020124', 'OR_mixedonly_20020221']; |
65 |
|
my $sound = ['OR_tr_20020124', 'OR_lc_20020124', 'split2', 'Soundex']; |
66 |
|
my $trigr = ['OR_lc_20020124', 'OR_trigrams_20020125']; |
67 |
|
# split6 is better than split13 or split10: it allows them to enter |
68 |
|
# shorter sequences when searching. |
69 |
|
my $isbn = ['split6', 'OR_isbn_20020127']; |
70 |
|
|
71 |
my $cwd = cwd; |
my $cwd = cwd; |
72 |
|
|
73 |
|
my $droot = shift or die "Usage: $0 <options> Document-Rootdirectories"; |
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, |
'title' => $text, |
87 |
'about' => $stem, |
'title' => $wplus, |
88 |
'text' => $text, |
# 'title' => $stem, |
89 |
|
'aboutauthor' => $text, |
90 |
|
'aboutauthor' => $wplus, |
91 |
|
# 'aboutauthor' => $stem, |
92 |
|
'desc' => $text, |
93 |
|
'desc' => $wplus, |
94 |
|
'abstract' => $text, |
95 |
|
'abstract' => $wplus, |
96 |
'author' => $text, |
'author' => $text, |
97 |
|
# 'author' => $sound, |
98 |
'colophon' => $text, |
'colophon' => $text, |
99 |
'author' => $sound, |
'colophon' => $wplus, |
100 |
'isbn' => $text, |
'isbn' => $isbn, |
101 |
] |
] |
102 |
); |
); |
103 |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
104 |
|
|
105 |
my ($did, $value); |
my ($did, $value); |
106 |
|
binmode STDOUT, ":utf8"; |
107 |
while (($did, $value) = each %D) { |
while (($did, $value) = each %D) { |
108 |
my $record = $layout->split($value); |
my $record = $layout->split($value); |
109 |
my $headline = $record->{title}; |
my $headline = $record->{title}; |
114 |
%{$record}); |
%{$record}); |
115 |
} |
} |
116 |
$tb->set(top=>1); |
$tb->set(top=>1); |
117 |
|
|
118 |
|
my $tritb = $db->create_table( |
119 |
|
name => "$OPT{table}_fallback", |
120 |
|
attr => [qw(docid headline)], # name |
121 |
|
# "headline" |
122 |
|
# only for |
123 |
|
# sman |
124 |
|
invindex => [ headline => $trigr ], |
125 |
|
); |
126 |
|
my %dict; |
127 |
|
for my $f ($tb->fields) { |
128 |
|
my(@idx) = @{$tb->table->{inverted}{$f} || []}; |
129 |
|
for my $idx (@idx) { |
130 |
|
my $name = $idx->name; |
131 |
|
next if $name =~ /(_|\b)(mixedonly|Stem|Soundex)(\b|_)/; |
132 |
|
# irrelevant for alternatives |
133 |
|
my @keys = $idx->keys; |
134 |
|
@dict{@keys} = (); |
135 |
|
} |
136 |
|
} |
137 |
|
my @dictkeys = grep s/^p//, keys %dict; |
138 |
|
my $maxdebug = 5; |
139 |
|
for my $headline (@dictkeys) { |
140 |
|
if ($maxdebug && $headline =~ /[^\040-\177]/) { |
141 |
|
Dump $headline; |
142 |
|
$maxdebug--; |
143 |
|
} |
144 |
|
# printf "%s\n", substr($headline,0,60); |
145 |
|
$tritb->insert(docid => $headline, headline => $headline); |
146 |
|
} |
147 |
|
$tritb->set(top=>1); |
148 |
|
$tritb->close; |
149 |
$tb->close(); |
$tb->close(); |
150 |
$db->close(); |
$db->close(); |
151 |
|
|
152 |
|
# Atomically relinking symlink: now we have a new database with a very |
153 |
|
# long name like oreilly_de_catalog-2002-01-28_16:12_16467 and we want |
154 |
|
# that database to be accessible with the oreilly_de_catalog name. |
155 |
|
|
156 |
|
use File::Spec; |
157 |
|
my $dir = "$OPT{database}-$jobid"; |
158 |
|
my $slwant = File::Spec->catdir($OPT{dir}, $OPT{database}); |
159 |
|
my $sltmp = File::Spec->catdir($OPT{dir}, "$OPT{database}-$$"); |
160 |
|
unlink $sltmp; # may fail |
161 |
|
symlink $dir, $sltmp or die "Couldn't symlink $dir, $sltmp: $!"; |
162 |
|
rename $sltmp, $slwant or die "Couldn't rename $sltmp, $slwant: $!"; |
163 |
|
warn "$slwant now points to $dir"; |
164 |
|
system("chmod 777 $slwant/*/read")==0 or die; |
165 |
|
|
166 |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
167 |
|
|
168 |
|
|
178 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
179 |
|
|
180 |
B<index_ora> |
B<index_ora> |
|
[B<-clean>] [B<-noclean>] |
|
181 |
[B<-database> I<dbname>] |
[B<-database> I<dbname>] |
182 |
[B<-dir> I<directory>] |
[B<-dir> I<directory>] |
183 |
[B<-table> I<table name>] |
[B<-table> I<table name>] |
189 |
|
|
190 |
=over 5 |
=over 5 |
191 |
|
|
|
=item B<-clean> / B<-noclean> |
|
|
|
|
|
Clean the table before indexing. Default is B<off>. |
|
|
|
|
192 |
=item B<-database> I<dbname> |
=item B<-database> I<dbname> |
193 |
|
|
194 |
Specify database name. Default is F<DB>. |
Specify database name. Default is F<DB>. |