/[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

Annotation of /cvs-head/script/index_ora

Parent Directory Parent Directory | Revision Log Revision Log


Revision 55 - (hide annotations)
Mon Dec 31 14:07:22 2001 UTC (22 years, 5 months ago) by ulpfr
File size: 4017 byte(s)
Traverses 'catalog' and generates a simple index.  Searching with
'sman -tab ora' sort of works.

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

Properties

Name Value
cvs2svn:cvs-rev 1.1

  ViewVC Help
Powered by ViewVC 1.1.26