1 |
#!/usr/bin/perl -w |
2 |
# -*- Mode: Perl -*- |
3 |
# $Basename$ |
4 |
# $Revision: 1.4 $ |
5 |
# Author : Ulrich Pfeifer |
6 |
# Created On : Mon Dec 31 13:57:11 2001 |
7 |
# Last Modified By: Ulrich Pfeifer |
8 |
# Last Modified On: Fri Jan 4 15:59:20 2002 |
9 |
# Language : CPerl |
10 |
# |
11 |
# (C) Copyright 2001, UUNET Deutschland GmbH, Germany |
12 |
# |
13 |
|
14 |
use strict; |
15 |
use File::Path; |
16 |
use DB_File; |
17 |
use Getopt::Long; |
18 |
use Cwd; |
19 |
|
20 |
require WAIT::Config; |
21 |
require WAIT::Database; |
22 |
require WAIT::Parse::Ora; |
23 |
require WAIT::Document::Ora; |
24 |
require WAIT::InvertedIndex; |
25 |
|
26 |
|
27 |
$DB_BTREE->{'cachesize'} = 200_000 ; |
28 |
|
29 |
my %OPT = (clean => 0, |
30 |
database => 'DB', |
31 |
dir => $WAIT::Config->{WAIT_home} || '/tmp', |
32 |
table => 'ora', |
33 |
); |
34 |
|
35 |
GetOptions(\%OPT, |
36 |
'clean!', |
37 |
'database=s', |
38 |
'dir=s', |
39 |
'table=s', |
40 |
) || die "Usage: ...\n"; |
41 |
|
42 |
if ($OPT{clean} and -d "$OPT{dir}/$OPT{database}") { |
43 |
my $tmp = WAIT::Database->open(name => $OPT{database}, |
44 |
'directory' => $OPT{dir}) |
45 |
or die "Could not open table $OPT{table}: $@\n"; |
46 |
my $tbl = $tmp->table(name => $OPT{table}); |
47 |
$tbl->drop if $tbl; |
48 |
rmtree("$OPT{dir}/$OPT{database}/$OPT{table}", 1, 1) |
49 |
if -d "$OPT{dir}/$OPT{database}/$OPT{table}"; |
50 |
$tmp->close; |
51 |
} |
52 |
|
53 |
my $db; |
54 |
unless (-d "$OPT{dir}/$OPT{database}") { |
55 |
$db = WAIT::Database->create(name => $OPT{database}, |
56 |
'directory' => $OPT{dir}) |
57 |
or die "Could not open database $OPT{database}: $@\n"; |
58 |
} |
59 |
else { |
60 |
$db = WAIT::Database->open(name => $OPT{database}, |
61 |
'directory' => $OPT{dir}) |
62 |
or die "Could not open table $OPT{table}: $@\n"; |
63 |
} |
64 |
|
65 |
my $layout = new WAIT::Parse::Ora; |
66 |
|
67 |
my $stem = ['isotr', 'isolc', 'split2', 'stop', 'Stem']; |
68 |
my $text = [{ |
69 |
'prefix' => ['isotr', 'isolc'], |
70 |
'intervall' => ['isotr', 'isolc'], |
71 |
}, |
72 |
'isotr', 'isolc', 'split2', 'stop']; |
73 |
my $sound = ['isotr', 'isolc', 'split2', 'Soundex'],; |
74 |
|
75 |
my $cwd = cwd; |
76 |
|
77 |
my %D; |
78 |
my $access = tie %D, 'WAIT::Document::Ora', @ARGV, |
79 |
or die "Couldn't tie to file: $!\n"; |
80 |
|
81 |
my $tb = $db->create_table(name => $OPT{table}, |
82 |
attr => ['author', 'isbn', 'title', |
83 |
'headline', 'docid'], |
84 |
layout => $layout, |
85 |
access => $access, |
86 |
invindex => |
87 |
[ |
88 |
'title' => $stem, |
89 |
'about' => $stem, |
90 |
'text' => $text, |
91 |
'author' => $text, |
92 |
'colophon' => $text, |
93 |
'author' => $sound, |
94 |
'isbn' => $text, |
95 |
] |
96 |
); |
97 |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
98 |
|
99 |
my ($did, $value); |
100 |
while (($did, $value) = each %D) { |
101 |
my $record = $layout->split($value); |
102 |
my $headline = $record->{title}; |
103 |
$headline =~ s/\s+/ /sg; |
104 |
printf "%15s %s\n", $record->{isbn}, substr($headline,0,60); |
105 |
$tb->insert('docid' => $did, |
106 |
headline => $headline, |
107 |
%{$record}); |
108 |
} |
109 |
$tb->set(top=>1); |
110 |
$tb->close(); |
111 |
$db->close(); |
112 |
|
113 |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
114 |
|
115 |
|
116 |
__END__ |
117 |
## ################################################################### |
118 |
## pod |
119 |
## ################################################################### |
120 |
|
121 |
=head1 NAME |
122 |
|
123 |
index_ora - generate an WAIT index for O'Reilly catalog |
124 |
|
125 |
=head1 SYNOPSIS |
126 |
|
127 |
B<index_ora> |
128 |
[B<-clean>] [B<-noclean>] |
129 |
[B<-database> I<dbname>] |
130 |
[B<-dir> I<directory>] |
131 |
[B<-table> I<table name>] |
132 |
I<directory> |
133 |
|
134 |
=head1 DESCRIPTION |
135 |
|
136 |
=head1 OPTIONS |
137 |
|
138 |
=over 5 |
139 |
|
140 |
=item B<-clean> / B<-noclean> |
141 |
|
142 |
Clean the table before indexing. Default is B<off>. |
143 |
|
144 |
=item B<-database> I<dbname> |
145 |
|
146 |
Specify database name. Default is F<DB>. |
147 |
|
148 |
=item B<-dir> I<directory> |
149 |
|
150 |
Alternate directory where databases are located. Default is the |
151 |
directory specified during configuration of WAIT. |
152 |
|
153 |
=item B<-table> I<table name> |
154 |
|
155 |
Specify an alternate table name. Default is C<ora>. |
156 |
|
157 |
=head1 AUTHOR |
158 |
|
159 |
Ulrich Pfeifer E<lt>F<pfeifer@wait.de>E<gt> |
160 |
|