#!/usr/bin/perl ################################################ # PaW.cgi # Online Interface to use PaW Serch Engine # Author: Fabiana Prabhakar # Version: 1.0 ################################################ use IO::Socket; use CGI ':standard'; use Switch; # START MAIN # Print HTML form print_html(); #Connect to the Socket $socket = IO::Socket::INET->new( Proto => "tcp", PeerAddr => '128.180.120.88', #PeerAddr => '127.0.0.1', PeerPort => '44444') or die "cannot connect to socket"; #If the button Search is pressed if (param('Action') eq 'Search'){ #Counter Printed in the Results $idx=1; #Get query from the user $key = param('query'); #Get the query type $which_radio_button=1; $selection=param('radio_buttons'); switch ($selection){ case 'TF-IDF' {$which_radio_button = 1}; case 'PaW Score' {$which_radio_button = 4}; case 'TF-IDF+PageRank' {$which_radio_button = 2}; case 'TF-IDF+Clever' {$which_radio_button = 3}; case 'Clever' {$which_radio_button = 5}; } #Phrase Search #if ($key=~m/"/){ # #TF-IDF # if ($which_radio_button eq 1){ # $which_radio_button = 3; # } # #PaW Score # if ($which_radio_button eq 2){ # $which_radio_button = 4; # } # $key=~ s/"//g; #} #Send query to server $key="$which_radio_button;$key\n"; $socket->send($key); $| = 1; #Read from the Socket #Server Message Format \n\n...\n\nEND $result=""; $leftover=""; $truncate = 0; while (1){ $result=""; $socket->recv($result, 3000); $result = $leftover.$result; $truncate = 0; #Server adds END to the last result if ($result=~m/END/){ $isLast=true; $result=~ s/END//; } $string = substr($result,length($result)-1,1); if ($string ne "\n"){ $truncate=1; } #Treat New Line if ($result =~ m/\n/){ @res1 = split(/\n/, $result); for ($index=0;$index<@res1-$truncate;$index++) { if ($res1[$index] =~ m/#PAWSEARCH#/){ @res2 = split(/#PAWSEARCH#/, $res1[$index]); for ($index2=0;$index2<@res2;$index2++) { $URL = $res2[$index2]; $index2++; $atext = $res2[$index2]; print "$idx. "; print "$atext
"; print "Url: $URL

"; $idx++; } } else { #Prints the exceptions print "$res1[$index]
"; } } if ($truncate eq 1){ $leftover = $res1[$index]; } else{ $leftover = ""; } } #$| = 1; if ($isLast eq true) { last; } #print print_end; } } close $socket; # END OF MAIN #Prints the HTML form sub print_html(){ $image = "PaW.jpg"; $align="center"; $img_size="50"; print header; print start_html("PaW Search Engine"); print ""; print "
"; print ""; print "

PaW Search Engine

\n"; print "

"; print start_form; print "

"; print textfield(-name=>'query',-default=>'', -size=>50); print submit('Action','Search'); print "
"; print "
"; print radio_group(-name=>'radio_buttons',-values=>['TF-IDF','TF-IDF+PageRank','TF-IDF+Clever','Clever','PaW Score']); print "
"; print "
"; print "

"; } sub print_end{ print ""; print endform; print end_html; }