]> git.donarmstrong.com Git - infobot.git/commitdiff
closed 17379 -- W3Search.pl gives duplicate output
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 11 Aug 2000 12:10:19 +0000 (12:10 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 11 Aug 2000 12:10:19 +0000 (12:10 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@30 c11ca15a-4712-0410-83d8-924469b57eb5

src/Modules/W3Search.pl

index 72d78d3ccef5ed8a19ec85404b7586cfa24780be..470bb8d7a89c1c62a2ad95c4896250caba419b81 100644 (file)
@@ -32,21 +32,26 @@ sub W3Search {
     $Search->http_proxy($main::param{'httpProxy'}) if (&main::IsParam("httpProxy"));
     my $max = $Search->maximum_to_retrieve(10);        # DOES NOT WORK.
 
-    my ($Result, $count);
-    my $r;
-    ### TODO: don't duplicate hosts. minimize like with the files
-    ###                function.
+    my (%results, $count, $r);
     while ($r = $Search->next_result()) {
-       if ($Result) {
-           $Result .= " or ".$r->url();
+       my $url = $r->url();
+
+       ### TODO: fix regex.
+       ### TODO: use array to preserve order.
+       if ($url =~ /^http:\/\/([\w\.]*)/) {
+           my $hostname = $1;
+           next if (exists $results{$hostname});
+           $results{$hostname} = $url;
        } else {
-           $Result = $r->url();
+           &main::DEBUG("W3S: url isn't good? ($url).");
        }
+
        last if ++$count >= $maxshow;
     }
 
-    if ($Result) {
-       $retval = "$where says \002$what\002 is at $Result";
+    if (scalar keys %results) {
+       $retval = "$where says \002$what\002 is at ".
+               join(' or ', map { $results{$_} } sort keys %results);
     }
 
     &main::performStrictReply($retval);