#!/usr/bin/perl # # search-report: report on search queries and results from visitors # # Copyright (c) 2000 Chris Lightfoot. All Rights Reserved. # # $Log: search-report,v $ # Revision 1.1 2000/08/20 21:38:27 chris # Initial revision # # $rcsid = '$Id: search-report,v 1.1 2000/08/20 21:38:27 chris Exp chris $'; sub http_unescape { my ($foo) = @_; $foo =~ tr/+/ /; $foo =~ s/%(..)/chr(hex($1))/ge; return $foo; } sub looks_like_query { my ($foo) = @_; return ($foo =~ /[A-Za-z0-9 +\-()]+/ and length($foo) > 3 and $foo !~ /^cache:/); } $time = scalar(localtime()); print < What the Search Engine Found

What the Search Engine Found

[ Home Page ]

This is a compilation of search-engine queries (established from the HTTP Referer: field in the logs) which led people to pages on this site. The script which generated this report is available as http://www.ex-parrot.com/~chris/stuff/search-report. You can also read an explanation of what this is all about.

This was (sort of) current at $time.

EOF @search_args = ("q", "qr", "p", "ask", "MT", "query", "qt", "search", "ask"); while ($l = ) { ($url, $referrer) = $l =~ /"(?:GET|POST) ([^ ]+) [^"]*" [0-9]+ [0-9]+ "([^"]+)/; $url =~ s/\/$//; $url = http_unescape($url); if ($referrer eq '-') { next; } ($script, $args) = $referrer =~ /([^?]+)\?(.*)/; if ($args ne undef) { %a = ( ); @foo = split('&', $args); foreach $f (@foo) { ($k, $v) = split('=', $f); $a{http_unescape($k)} = http_unescape($v); } foreach $s (@search_args) { if (defined($a{$s}) and looks_like_query($a{$s})) { $res{$url}->{$a{$s}}++; last; } } } } foreach $url (keys %res) { print < EOF $first = 1; foreach $search (sort(keys(%{$res{$url}}))) { if (!$first) { print < EOF } print <$search EOF $first = 0; } } print <

Copyright (c) 2000 Chris Lightfoot. All Rights Reserved.

EOF
Somebody found... by searching for...
$url