summaryrefslogtreecommitdiff
path: root/bucky2/cgi-bin/api/autocomplete
blob: ac42f06a7b44d4f9395cbe16f30d1dd3394ab9e4 (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
#!/usr/bin/perl

use lib "../../lib";
use Bucky;
use Bucky::Session;
use Bucky::Search;
my $bucky = new Bucky;
my $session = new Bucky::Session;
my $q = $session->param('q');

print "Content-type: text/plain\n\n";

if (length $q)
	{
	my $search = new Bucky::Search;
	my $guess = $search->autocomplete($q);
	my $results = $search->search_light($guess->{'full'}, 0, 40);
	# my $terms = $results->{terms};

	print $guess->{'tail'} || "_";
	print "\n";
	foreach my $result (@{$results->{'results'}})
		{
		my $thread = $results->{'threads'}->{ $result->{'thread'} };
		my $comment = $results->{'comments'}->{ $result->{'comment'} };
		my $file = $results->{'files'}->{ $result->{'file'} };
		my $z_thread = $thread->{'id'};
		my $z_title = $thread->{'title'};
		my $z_file = $file->{'id'};
		my $z_subtitle = $file->{'filename'};
		$z_subtitle =~ s/[^a-zA-Z0-9 ()\.]/ /g;
		$z_subtitle =~ s/_/ /g;
		$z_subtitle =~ s/\s+/ /g;
		$z_subtitle =~ s/^\s//;
		$z_subtitle =~ s/\s$//;
		print join "\t", $z_thread, $z_title, $z_subtitle, $z_file;
		print "\n";
		}
	}
else
	{
	print "\n";
	}
1;