7 #this program takes, as CGI params, a query string "words"
8 #a syntax string "bool" (and|or), values of Y or N for the
9 #variables of the form hasVideo, hasAudio, hasImage, etc.
10 #and a variable topic corresponding to the desired topic title
11 #it then munges these variables into an appropriate request to htdig,
12 # does this request and forwards the results to the user
14 $searchhost='http://prod.indymedia.nl/cgi-bin/htsearch';
17 $hasVideo=param('hasVideo');
18 $hasAudio=param('hasAudio');
19 $hasImages=param('hasImages');
20 $topic=param('topic');
21 @topic_words=split(/\s+/,$topic);
25 @words=split (/\s+/,param('words')) if param('words');
26 push @words,@topic_words;
30 $querywords=join " AND ", @words;
33 $querywords=join " OR ", @words;
36 $querywords =~ s/\(\)/ /g;
37 $querywords="($querywords)";
40 if ($hasVideo eq "Y" || $hasAudio eq "Y" || $hasImages eq "Y"){
47 if ($hasVideo eq "Y"){
51 $querywords.=" RealVideo OR Video";
55 if ($hasAudio eq "Y"){
59 $querywords.=" RealAudio OR Audio";
63 if ($hasImages eq "Y"){
67 $querywords.=" ImagesGif OR ImagesJpeg";
73 $querywords=uri_escape($querywords,"^A-Za-z0-9");
75 $query="words=$querywords&format=builtin-long&sort=score&method=boolean";
77 # propagate the config parameter if it is set - rob
78 $config=param('config');
79 $query.="&config=$config" if $config;
83 $ua = new LWP::UserAgent;
84 $ua->agent("AgentName/0.1 " . $ua->agent);
87 my $req = new HTTP::Request POST => $searchhost;
88 $req->content_type('application/x-www-form-urlencoded');
89 $req->content($query);
91 # Pass request to the user agent and get a response back
92 my $res = $ua->request($req);
94 # Check the outcome of the response
95 if ($res->is_success) {
100 print "Search engine temporarily unavailable\n";