/[bfilter]/trunk/bfilter.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/bfilter.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Tue Sep 7 17:44:56 2004 UTC (19 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 1619 byte(s)
added path and headline to index, html_pre, html_mid, html_post JavaScript
variables for result html

1 #!/usr/bin/perl -w
2 #
3
4 use strict;
5 use locale;
6
7 # maximum entries
8 my $max = 0;
9 # minimum letters to search by
10 my $min_len = 2;
11 # if more than x elements, warn to increase min_len
12 my $increase_at = 500;
13
14 my $debug = 1;
15
16 sub print_file {
17 my $f = shift || return;
18 open(F, $f) || die "$f: $!";
19 while(<F>) {
20 print;
21 }
22 close(F);
23 }
24
25 print qq{
26 var headlines = Array();
27 };
28
29 my @part_arr;
30 my $last_part = '';
31 my $total = 0;
32
33 my $max_elements = 0;
34
35 while(<STDIN>) {
36 chomp;
37
38 my ($path,$headline) = split(/\t+/,$_,2);
39
40 # escape single quote
41 $headline =~ s/'/\\'/g;
42
43 # split into min_len part and rest
44 my ($part,$rest) = ( substr($headline,0,$min_len), substr($headline,$min_len) );
45
46 # make part lowercase
47 $part = lc($part);
48
49 $last_part = $part if (! $last_part);
50
51 # new part?
52 if ($part ne $last_part) {
53 print STDERR $last_part,"\t",$#part_arr+1,"\n" if ($debug && $#part_arr > $increase_at);
54 $max_elements = $#part_arr if ($#part_arr > $max_elements);
55 print "headlines['$last_part'] = [\n ",join(",\n ",@part_arr),"];\n" if (@part_arr);
56 $total += $#part_arr;
57 @part_arr = ();
58 $last_part = $part;
59 }
60 push @part_arr, "['$path','$headline']";
61
62 # break out?
63 last if ($max && $total > $max);
64 }
65
66 print "headlines['$last_part'] = [\n ",join(",\n ",@part_arr),"];\n" if (@part_arr);
67 print qq{
68
69 var min_len = $min_len;
70 var html_pre = '<br/><a href="../';
71 var html_mid = '">';
72 var html_post = '</a>';
73
74 // index elements: $total
75
76 };
77
78 print STDERR "You have more than $increase_at elements, so you should\nincrease min_len to ",$min_len+1," or higher for performance benefit.\n" if ($max_elements > $increase_at);

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26