summaryrefslogtreecommitdiff
path: root/bucky2/bin/build-autocomplete
blob: d9a62fd1e01f207ed0bc3f74c5b2720f6e30d61f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
use lib "../lib";
use Bucky;
use Bucky::Search;
use Data::Dumper;
use DB_File;

my $file = "auto.db";

my $search = new Bucky::Search;

my $index = $search->index;
my $auto_index = $search->auto_index_write;

my $partials = {};
my $partials_with_media = {};
foreach my $word (keys %$index)
	{
	# goatse operator
	my $count =()= $index->{$word} =~ /,/g;

	next unless $word;

	my $par = '';
	my @letters = split "", $word;
	for (my $i = 0; $i < scalar @letters; $i++)
		{
		$par .= $letters[$i];
		if (! exists $partials->{$par} || $partials->{$par}->[0] < $count)
			{
			$partials->{$par} = [$count,$word];
			}
		}
	}
# don't autocomplete if we match a word
foreach my $word (keys %$index)
	{
	$partials->{$word}->[1] = $word
	}

foreach my $par (sort keys %$partials)
	{
	$auto_index->{$par} = $partials->{$par}->[1];
	}
$search->auto_index_close;

print "NEW: " ; system("/bin/ls", "-l", "./$file");
print "OLD: " ; system("/bin/ls", "-l", "../cgi-bin/$file");
system("/bin/mv", "../cgi-bin/$file", "../cgi-bin/$file.1");
system("/bin/mv", "./$file", "../cgi-bin/$file");

exit;