Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Last Search Terms

Quote Reply
Last Search Terms
 
Quote:
Btw: Do you know, how i can give out the last searched terms? Alex wrote inother thread this function is inside,
but i dont know where and how to do.

In short... no. I've been looking at that actually today. I'd like to be able to have a page that ranks the terms, and lets people search on them (see my earlier post on pre-compiled searches).

Right now it's more of an admin feature, but it's important for a bunch of us to have more user access to it, so hopefully someone has done it, or will do it shortly Wink

Quote Reply
Re: Last Search Terms In reply to
It's pretty easy to do:

Code:
sub top5 {
# -----------------------------------------------
# Returns a list of the top5 searched terms.
#
my ($in) = shift; # Needed for $in->escape
my $search = new Links: BSQL $LINKS{admin_root_path} . "/defs/Search_Log.def";

# Let's get a list of the top 5 terms ordered by number of times someone
# has searched on them.
my $results = $search->query ( { Term => '*', sb => 'Count', so => 'DESC', mh => 5 } );
my $output = '';
my $term_q;
if ($seach->hits) {
foreach my $term (@{$results}) {
$term = $search->array_to_hash($term);
$term_q = $in->escape($term);
print qq~
<a href="$LINKS{db_cgi_url}/search.cgi?query=$term_q">$term</a>
~;
}
}
else {
$output = "Sorry no one has searched for anything yet.";
}
return $output;
}

Looks like it should work. Then you could just call $output = &top5($in) and get a list of the top5 searched terms.

ps: I made two changes to previous version.

Hope this helps,

Alex

[This message has been edited by Alex (edited December 06, 1999).]
Quote Reply
Re: Last Search Terms In reply to
Hi Alex...

I tried your code in a simple cgi. And I got this error: "DBSQL (-580635): Fatal Error: Invalid argument type 'Term' passed to query"

My file is this way:

Code:
#!/usr/local/bin/perl

# Load required modules.
# ---------------------------------------------------
use strict;
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib 'admin';
use Links;
use Links: B_Utils;
use Links::HTML_Templates;
use Links: BSQL;
$|++;

my $in = new CGI;
print $in->header('text/html');

my $top5 = &top5 ($in);
print $top5;

sub top5 {
# -----------------------------------------------
# Returns a list of the top5 searched terms.
#
my ($in) = shift; # Needed for $in->escape

my $search = new Links: BSQL $LINKS{admin_root_path} . "/defs/Links.def";

# Let's get a list of the top 5 terms ordered by number of times someone
# has searched on them.
my $results = $search->query ( Term => '*', sb => 'Count', so => 'DESC', mh => 5 );
my $output = '';
my $term_q;
if ($search->hits) {
foreach my $term (@{$results}) {
$term = $search->array_to_hash($term);
$term_q = $in->escape($term);
print qq~
<a href="$LINKS{db_cgi_url}/busca.cgi?query=$term_q">$term</a>
~;
}
}
else {
$output = "Sorry no one has searched for anything yet.";
}
return $output;
}
Quote Reply
Re: Last Search Terms In reply to
Well, I changed
Code:
my $results = $search->query ( Term => '*', sb => 'Count', so => 'DESC', mh => 3 );
to
Code:
my $results = $search->query ( { Term => '*', sb => 'Count', so => 'DESC', mh => 3 } );

and it is working, but I keep getting "Sorry no one has searched for anything yet" and I have over 100 keywords..

Wasnīt I supossed to use Search_Log.def instead of Links.def?
I tried and it worked, but intead of the keyword i get HASH (DEFH x 88H), I mean, hexadecimal numbers...
Quote Reply
Re: Last Search Terms In reply to
You are right, here's a corrected version:

Code:
sub top5 {
# -----------------------------------------------
# Returns a list of the top5 searched terms.
#
my ($in) = shift; # Needed for $in->escape
my $search = new Links: BSQL $LINKS{admin_root_path} . "/defs/Search_Log.def";

# Let's get a list of the top 5 terms ordered by number of times someone
# has searched on them.
my $results = $search->query ( { Term => '*', sb => 'Count', so => 'DESC', mh => 5 } );
my $output = '';
my $term_q;
if ($seach->hits) {
foreach my $term (@{$results}) {
$term = $search->array_to_hash($term);
$term_q = $in->escape($term->{Term});
print qq~
<a href="$LINKS{db_cgi_url}/search.cgi?query=$term_q">${$term}{Term}</a>
~;
}
}
else {
$output = "Sorry no one has searched for anything yet.";
}
return $output;
}

Cheers,

Alex
Quote Reply
Re: Last Search Terms In reply to
Ok Alex, now I got this error:

"DBSQL (-653547): Fatal Error: Unable to execute query: SELECT * FROM Search_Log ORDER BY Count DESC LIMIT 0, 5 . Reason: Got error 127 from table handler"

Is it a problem with my tables?
I am using version 1.1
Quote Reply
Re: Last Search Terms In reply to
Well, everything seems to be ok.
Its working perfectly.

Thanks Alex....
Quote Reply
Re: Last Search Terms In reply to
May you kill the smileys inside the text?

Should i save this to an own top5.cgi and call it e.g. in a new window? It looks like a sub-routine, but where to insert and how to call?

This one should show the 5 most searched keywords and the number they were called at all.

How can i do another list, showing the most searched passwords all all? (order all keywords for number of calls)

Robert

[This message has been edited by Robert (edited December 07, 1999).]

[This message has been edited by Robert (edited December 07, 1999).]
Quote Reply
Re: Last Search Terms In reply to
You could add this to HTML_Templates.pm and then add:

top5 => \&top5

to the globals. Then whenever you use <%top5%> it will display it.

Cheers,

Alex
Quote Reply
Re: Last Search Terms In reply to
Nice to have some hints here, but it seems it is to less for my little brain.
So where should i insert this sub; how can i call it from a template.

Robert
Quote Reply
Re: Last Search Terms In reply to
I have insert the sub inside
HTML_Templates.pm
I have set top5 => /&top5 to Globals
but i got an error while building
I have set the sub to @export, but it fails again ???
Quote Reply
Re: Last Search Terms In reply to
What does the error say? Also try typing perl -c HTML_Templates.pm to see if there are any syntax errors.

Cheers,

Alex
Quote Reply
Re: Last Search Terms In reply to
The apache-error-log says nothing special.
May you send the whole text without smileys and complete instructions again, please?
Like:
1. Insert the sub5 to HTML_Templates.pm
and to GLOBALS:
top5 => \&top5
(Nothing else???)
2. Build in a template <%top5%>

Thatīs it?
Quote Reply
Re: Last Search Terms In reply to
I agree ! Alex should kill at least the colon-D smiley, since that's such a part of LinkSQL that it causes a lot of problems.

I'm not sure where you are having the problems. I don't see a full explanation of why it's not working.

The smiley is in "Links: BSQL" and all you need to do is add another colon and a capital D to join that into the package reference.
Links..DBSQL make the . :

Life would be so much easier if the cute smileys would go away....

Quote Reply
Re: Last Search Terms In reply to
Ok...

1) there is a typpo in the "corrected" version above, there is a 'seach' instead of 'search' which causes a -strict error.

2) I put this into HTML_Templates.pm, and in the query, I get the following error:
<B>Can't call method "escape" on unblessed reference at admin/Links/HTML_Templates.pm line 1014. </B>
Again, a -strict error.


Quote Reply
Re: Last Search Terms In reply to
Im still at the same point:

Can't call method "escape" on unblessed reference at admin/Links/HTML_Templates.pm line 764.

And now?

[This message has been edited by Robert (edited January 15, 2000).]
Quote Reply
Re: Last Search Terms In reply to
I had a disaster of a december, and I still have a lot of stuff on hold. I never figured this out. I had hoped Alex would jump in <G>

I'm almost ready to need to start figuring out how to generate "include" files for my templates since I don't want to use SSI, and I'd like to generate, and put into include files, various parts of the database such as the search terms, top 10, etc. This will probably be my project starting the end of next week. I've got all my templates revised, and all my beta sites are finally on the same code revision. Now I still have to make it "live" <G> ... that's still 1b3.

Quote Reply
Re: Last Search Terms In reply to
I understand you :-(
The last days i prepared my links running till yet on two servers (one domain, one IP) to one linux at home. Next week ill get my new server (hopefully with the same installation as my one at home) and then i must do the third moving. :-(
But maybe the one day will come, when i could say: now itīs finished.
Quote Reply
Re: Last Search Terms In reply to
Ok, try this one, please:

Code:
if ($search->hits) {
foreach my $term (@{$results}) {
$term = $search->array_to_hash($term);
$in=&escape($term);
$term_q = $in;
print qq~
<a href="$LINKS{db_cgi_url}/search.cgi?query=$term_q">${$term}{Term}</a>
~;
}
}
else {
$output = "Sorry no one has searched for anything yet.";
}
return $output;
Quote Reply
Re: Last Search Terms In reply to
Still two problems:

1. I wanna have the top5-tag inside my search.html, but the script writes it first then the rest of search.html.
2. The words are linked with garbage.

So solution could be for my to enter the code inside a own .cgi and show it in an extra window without links on it.
Tomorrow i will try it; its time to sleep ...