/[pgestraier]/trunk/data/indexer.pl
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 /trunk/data/indexer.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations)
Sat Sep 10 20:35:09 2005 UTC (18 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 2516 byte(s)
added node API

1 #!/usr/bin/perl -w
2
3 use strict;
4 use HyperEstraier;
5
6 # score for words in title
7 my $title_rank = 3;
8
9 open(my $t, "gzip -cd trivia.list.gz |") || die "can't open trivia.list.gz: $!";
10
11 # open the database
12 my $db = HyperEstraier::Database->new();
13 $db->open('casket', $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
14 # open node
15 my $node = HyperEstraier::Node->new("http://localhost:1978/node/trivia");
16 $node->set_auth('admin', 'admin');
17
18
19 my $header = 1;
20 my ($title, $year) = ('',undef);
21 my $in = 0;
22 my $trivia = '';
23 my @qv;
24
25 my ($all_years,$all_titles,$all_quotes);
26
27 sub qv {
28 my $t = shift || return;
29
30 sub qv_print {
31 my $v = shift || return '';
32 # $v =~ s/(.*)\s*,\s*(.+)/$2 $1/g;
33 push @qv, $v;
34 $all_quotes->{$v}++;
35 return '';
36 }
37 $t =~ s#([_'"])([^_'"]+?)\1 \(qv\)#qv_print($2)#ge;
38 }
39
40 my $i = 0;
41
42 while(<$t>) {
43 if ($header && /^=====+/) {
44 $header = 0;
45 next;
46 }
47 next if $header;
48
49 if (/^#\s+(.*)\s*$/) {
50 $title = $1;
51 if ($title =~ m#^("*)(.*)\1\s*\((\d+)\)(:?\s*\(\w+\))*$#) {
52 ($title, $year) = ($2,$3);
53 $all_titles->{$title}++;
54 $all_years->{$3}++;
55 } else {
56 $year = undef;
57 }
58
59 print "# $title ", ( $year ? "[$year]" : "" ), "\n";
60 next;
61
62 } elsif (/^-\s(.*)\s*$/) {
63 $in = 1;
64 $trivia = "$1\n";
65 qv($1);
66 } elsif (/^\s\s(.*)\s*$/) {
67 $trivia .= "$1\n";
68 qv($1);
69 } elsif (/^$/ && $in) {
70 $i++;
71 print "$i ";
72
73 # create a document object
74 my $doc = HyperEstraier::Document->new;
75
76 # add attributes to the document object
77 $doc->add_attr('@uri', "file://localhost/trivia/$i");
78
79 $doc->add_attr('@title', $title);
80 $doc->add_hidden_text(
81 ($title x $title_rank)
82 );
83
84 $doc->add_attr('@size', length($trivia));
85
86 $doc->add_attr('year', $year) if ($year);
87 foreach my $q (@qv) {
88 $doc->add_attr('quote', $q);
89 $doc->add_hidden_text($q);
90 }
91
92 # add the body text to the document object
93 $doc->add_text($trivia);
94
95
96 # register the document object to the database
97 $db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
98 $node->put_doc($doc);
99
100 $trivia = '';
101 @qv = ();
102 $in = 0;
103 } else {
104 print "#$_\n";
105 }
106
107 # last if ($i > 1000); # XXX remove this!
108 }
109
110 sub dump_data($$) {
111 my ($name,$hash) = @_;
112
113 open(my $fh, "> $name") || die "can't open $name: $!";
114
115 foreach my $k (sort keys %{$hash}) {
116 print $fh "$k\t",$hash->{$k},"\n";
117 }
118
119 close($fh);
120 }
121
122 dump_data('titles.data', $all_titles);
123 dump_data('quotes.data', $all_quotes);
124 dump_data('years.data', $all_years);
125
126 $db->sync();
127
128 #print "\noptimizing...\n";
129 #$db->optimize(0);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26