/[wait]/cvs-head/script/index_ora
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /cvs-head/script/index_ora

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations)
Fri Jan 4 15:11:54 2002 UTC (22 years, 4 months ago) by ulpfr
File size: 4181 byte(s)
Index and store ISBN

1 #!/usr/bin/perl -w
2 # -*- Mode: Perl -*-
3 # $Basename$
4 # $Revision: 1.3 $
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 'author' => $sound,
93 'isbn' => $text,
94 ]
95 );
96 die "Couldn't create table $OPT{table}: $@\n" unless $tb;
97
98 my ($did, $value);
99 while (($did, $value) = each %D) {
100 my $record = $layout->split($value);
101 my $headline = $record->{title};
102 $headline =~ s/\s+/ /sg;
103 printf "%15s %s\n", $record->{isbn}, substr($headline,0,60);
104 $tb->insert('docid' => $did,
105 headline => $headline,
106 %{$record});
107 }
108 $tb->set(top=>1);
109 $tb->close();
110 $db->close();
111
112 $WAIT::Config = $WAIT::Config; # make perl -w happy
113
114
115 __END__
116 ## ###################################################################
117 ## pod
118 ## ###################################################################
119
120 =head1 NAME
121
122 index_ora - generate an WAIT index for O'Reilly catalog
123
124 =head1 SYNOPSIS
125
126 B<index_ora>
127 [B<-clean>] [B<-noclean>]
128 [B<-database> I<dbname>]
129 [B<-dir> I<directory>]
130 [B<-table> I<table name>]
131 I<directory>
132
133 =head1 DESCRIPTION
134
135 =head1 OPTIONS
136
137 =over 5
138
139 =item B<-clean> / B<-noclean>
140
141 Clean the table before indexing. Default is B<off>.
142
143 =item B<-database> I<dbname>
144
145 Specify database name. Default is F<DB>.
146
147 =item B<-dir> I<directory>
148
149 Alternate directory where databases are located. Default is the
150 directory specified during configuration of WAIT.
151
152 =item B<-table> I<table name>
153
154 Specify an alternate table name. Default is C<ora>.
155
156 =head1 AUTHOR
157
158 Ulrich Pfeifer E<lt>F<pfeifer@wait.de>E<gt>
159

Properties

Name Value
cvs2svn:cvs-rev 1.3

  ViewVC Help
Powered by ViewVC 1.1.26