-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.pl
executable file
·51 lines (41 loc) · 1.35 KB
/
search.pl
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
#!/usr/bin/perl -w -CS -I.
# vim: textwidth=0 wrapmargin=0 shiftwidth=2 tabstop=2 expandtab softtabstop
# -CS forces stdin/out/err to be treated as utf8
use strict;
use utf8;
use Data::Dumper;
use CGI;
use JSON;
use ED::DevTracker::Config;
use ED::DevTracker::DB;
$ENV{'TZ'} = 'UTC';
my $config = ED::DevTracker::Config->new(file => "config.txt");
if (!defined($config)) {
failure("Couldn't find server-side config");
}
my $db = new ED::DevTracker::DB('config' => $config);
my $cgi = CGI->new;
print $cgi->header(-type => "application/json", -charset => "utf-8");
if (!defined($cgi->multi_param('search_text'))) {
failure("No search text supplied");
}
my $results = $db->ts_search($cgi->multi_param('search_text'), $cgi->multi_param('search_in_title'), $cgi->multi_param('search_in_precis'));
if (!defined($results)) {
failure("No results!");
}
my %status = ( 'status' => 'ok' );
$status{'results'} = $results;
my $json = to_json(\%status);
print $json;
exit(0);
###########################################################################
# Return Failure
###########################################################################
sub failure {
my $reason = shift;
my %status = ( 'status' => 'fail', 'reason' => $reason );
my $json = to_json(\%status);
print $json;
exit(0);
}
###########################################################################