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

Diff of /trunk/data/indexer.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 29 by dpavlin, Wed Jul 6 11:47:56 2005 UTC revision 59 by dpavlin, Thu May 25 18:46:49 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use HyperEstraier;  use Search::Estraier 0.06;
5    
6  # score for words in title  # score for words in title
7  my $title_rank = 3;  my $title_rank = 3;
8    
9  open(my $t, "gzip -cd trivia.list.gz |") || die "can't open trivia.list.gz: $!";  open(my $t, "gzip -cd trivia.list.gz |") || die "can't open trivia.list.gz: $!";
10    
11  # open the database  # open node
12  my $db = HyperEstraier::Database->new();  my $node = Search::Estraier::Node->new(
13  $db->open('casket', $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);          url => 'http://localhost:1978/node/trivia',
14            user => 'admin',
15            passwd => 'admin',
16            create => 1,
17    );
18    
19    
20  my $header = 1;  my $header = 1;
# Line 31  sub qv { Line 35  sub qv {
35                  $all_quotes->{$v}++;                  $all_quotes->{$v}++;
36                  return '';                  return '';
37          }          }
38          $t =~ s#([_'])([^_']+?)\1 \(qv\)#qv_print($2)#ge;          $t =~ s#([_'"])([^_'"]+?)\1 \(qv\)#qv_print($2)#ge;
39  }  }
40    
41  my $i = 0;  my $i = 0;
# Line 46  while(<$t>) { Line 50  while(<$t>) {
50          if (/^#\s+(.*)\s*$/) {          if (/^#\s+(.*)\s*$/) {
51                  $title = $1;                  $title = $1;
52                  if ($title =~ m#^("*)(.*)\1\s*\((\d+)\)(:?\s*\(\w+\))*$#) {                  if ($title =~ m#^("*)(.*)\1\s*\((\d+)\)(:?\s*\(\w+\))*$#) {
53                          $year = $3;                          ($title, $year) = ($2,$3);
54                          $all_titles->{$2}++;                          $all_titles->{$title}++;
55                          $all_years->{$3}++;                          $all_years->{$3}++;
56                  } else {                  } else {
57                          $year = undef;                          $year = undef;
# Line 68  while(<$t>) { Line 72  while(<$t>) {
72                  print "$i ";                  print "$i ";
73    
74                  # create a document object                  # create a document object
75                  my $doc = HyperEstraier::Document->new;                  my $doc = Search::Estraier::Document->new;
76    
77                  # add attributes to the document object                  # add attributes to the document object
78                  $doc->add_attr('@uri', "file://localhost/trivia/$i");                  $doc->add_attr('@uri', "file://localhost/trivia/$i");
79    
80                  $doc->add_attr('@title', $title);                  $doc->add_attr('@title', $title);
81                    $doc->add_hidden_text(
82                            ($title x $title_rank)
83                    );
84    
85                  $doc->add_attr('@size', length($trivia));                  $doc->add_attr('@size', length($trivia));
86    
87                  $doc->add_attr('year', $year) if ($year);                  $doc->add_attr('year', $year) if ($year);
# Line 83  while(<$t>) { Line 92  while(<$t>) {
92    
93                  # add the body text to the document object                  # add the body text to the document object
94                  $doc->add_text($trivia);                  $doc->add_text($trivia);
                 $doc->add_hidden_text(  
                         ($title x $title_rank)  
                 );  
95    
96    
97                  # register the document object to the database                  # register the document object to the database
98                  $db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);                  $node->put_doc($doc);
99    
100                  $trivia = '';                  $trivia = '';
101                  @qv = ();                  @qv = ();
# Line 113  sub dump_data($$) { Line 119  sub dump_data($$) {
119          close($fh);          close($fh);
120  }  }
121    
122  dump_data('titles.data', $all_titles);  #dump_data('titles.data', $all_titles);
123  dump_data('quotes.data', $all_quotes);  #dump_data('quotes.data', $all_quotes);
124  dump_data('years.data', $all_years);  #dump_data('years.data', $all_years);
125    
 #print "\noptimizing...\n";  
 #$db->optimize(0);  

Legend:
Removed from v.29  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26