Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

top 5 search terms global

Quote Reply
top 5 search terms global
Hello

I am trying to create a global that will Displays the top 5 search terms using GT searchlogger plug in.

can anyone help?


Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] top 5 search terms global In reply to
This may help:

http://gossamer-threads.com/...orum.cgi?post=126174

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] top 5 search terms global In reply to
Thanks Alex

but the links on that page are not active any more so I could not get the codes.

I am not a programer..
I tried the following code :

sub {
# -----------------------------------------------
# Returns a list of the Top5 Searched terms.
$search_db = $DB->table('SearchLog');
$search_db->select_options ('ORDER BY Results DESC', 'LIMIT 5');
$sth = $search_db->select;
while (my $row = $sth->fetchrow_hashref) {
my $output = ''; ## See Post below
my $term_q;
if ($Search->hits) {
foreach my $term (@{$results}) {
$term = $Search->array_to_hash($term);
$term_q = $in->escape($term->{Term});
$output .= 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;
}

and it is not working

can someone take a look and tell me what is wrong in it (if any is rightWink).


Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory

Last edited by:

pugdog: Dec 29, 2001, 5:09 PM
Quote Reply
Re: [katabd] top 5 search terms global In reply to
I know this is a bit dusty, but looking at the code,


$search_db->select_options ('ORDER BY Results DESC', 'LIMIT 5');


This would return the 5 keywords with the most "hits" rather than the most commonly searched terms. In the searchlogger 2.1 you'd want to 'ORDER BY HitCount DESC' to find the terms people are searching on the most.

BTW: I rewrote the SearchLogger to use different logic (it's probably a bit slower than Alex's version, but it does more), and to also track the daily keywords. I need to finish the Top_xx tags code and I can release it. I'm trying to figure out how to do this without having to have the user install the globals manually (I think alex gave some code to do that awhile back, but I haven't found it yet).








PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] top 5 search terms global In reply to
Hi

Thanks for the correction.. Yes that makes sense more.
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] top 5 search terms global In reply to
Another thing:

I don't usually edit posts, but in this case, (code errors/points) it helps to localize it.

Look at the post above, where I added the red comment.

you have "my $output" defined within the "while" block.

Once you exit that block, the $output variable goes out of scope, and disappears. Sometimes, errors are lost in plugin code, or globals, so you might not be getting the error. Running perl -c on a file will often catch it.

That might be one of the other problems. You need to define $output outside any block, inside the sub {} block.

BTW: that code fragment has other problems, missing } and $results is not defined either, but the point I wanted to make was the scope issue, and that is a big one.



PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Dec 29, 2001, 5:15 PM
Quote Reply
Re: [pugdog] top 5 search terms global In reply to
Quote:
You need to define $output outside any block, inside the sub {} block.

You don't need to predeclare if the variable stays within the current block. You still need to use my() though.

Last edited by:

RedRum: Dec 30, 2001, 3:29 AM
Quote Reply
Re: [RedRum] top 5 search terms global In reply to
What I meant, in the short hand, was the variable was defined with "my" inside the while loop.

You need to do that OUTSIDE the while loop, and _yes_ in this case, you _do_ need to pre-declare it, pre-set the scope, or otherwise tell the compiler what to do with the variable before it's actually "used".

Remember, Links SQL needs to be mod_perl compatible, and since you are first using the $output _inside_ a loop, then returning it outside the loop at the end of the routine, you do need to pre-declare it.

"my" sets the scope of the variable. If you don't like the term "pre-declare" then use the term "set the scope" before you use it.

I actually _like_ thinking in terms of pre-declare, since it brings me back to my early days, and it makes sure I have defined, set up, and set the scope on, all the variables I need to use.

Perl allows a lot of bad behavior, and that is good for quick and dirty programs as it was originally set up for, but OO Perl requires a whole different mindset, and programming style.

One of my constructs is I usually set the variables with "my" near where they are first used. But, I _only_ do that if that is only where they are going to be used -- ie: within a few lines of where they were originally declared. If not, I still define them at the top of the program, begining of the loop or block, or where it makes the most sense.

A great example is $sth used as the statement handle. If you only use it in the 2 lines required to set it, and then iterate it, it is fine to declare it with $my where it's first assigned. _but_ if you are going to use it multiple times, or with multiple options, it's better to define it at the top of the block, or subroutine, since it no longer belongs to a single statement, and in trying to maintain the code a few weeks or months later, you will start to wonder where $sth was originally scoped/declared and who owns it.

Most of Perl is creative and liberal use of white space and style. The more consistent you are, the more clear you are, the better your scripts will go together, and the easier they will be to read and maintain.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] top 5 search terms global In reply to
Quote:
and since you are first using the $output _inside_ a loop, then returning it outside the loop at the end of the routine, you do need to pre-declare it.

I know, that's what I was saying Wink


Quote:
$my

That would cause a hiccup :)

Quote:
The more consistent you are, the more clear you are, the better your scripts will go together, and the easier they will be to read and maintain.

Yup, thats why I use strict and OO programming in my scripts.

btw, above, $sth and $search_db also need to be declared with my()

Also Im not sure where $Search and $results are from.

Last edited by:

RedRum: Dec 30, 2001, 7:45 AM
Quote Reply
Re: [katabd] top 5 search terms global In reply to
Here is an example that should work:

Code:
sub {
# -----------------------------------------------
# Returns a list of the Top5 Searched terms.

my (@output,$db,$sth);

$db = $DB->table('SearchLog');
$db->select_options ('ORDER BY HitCount DESC', 'LIMIT 5');
$sth = $db->select;

while (my $row = $sth->fetchrow_hashref) {
push @output, qq~<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a>~;
}

return $#output > -1 ? join('-', @output) || 'No terms yet!';

}

Btw it looks like you are using Links SQL 1.13?




Last edited by:

RedRum: Dec 30, 2001, 7:57 AM
Quote Reply
Re: [RedRum] top 5 search terms global In reply to
BTW: check the Plugins Forum. I uploaded a modified SearchLogger plugin that allows you to specify the number of terms, and whether you want totals, recent or daily keywords.

Requires 2.1 to run, though.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [RedRum] top 5 search terms global In reply to
Hi

For some reason this code is not working with 2.1 anymore..

I am getting:

a fatal error had occured

GT::Config (20636): Unable to compile '_g_top_keyword'' in file '/home/virtual/site315/fst/var/www/cgi-bin/links/admin/templates/default/globals.txt': Missing right curly or square bracket at (eval 2) line 2, at end of line
syntax error at (eval 2) line 2, at EOF
at /home/virtual/site315/fst/var/www/cgi-bin/links/admin/GT/Template.pm line 461.



any ideas
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] top 5 search terms global In reply to
Hmm strange. I don't see any missing curly brackets.

Could you paste the exact code giving the error?
Quote Reply
Re: [RedRum] top 5 search terms global In reply to
Hi



sub {
# -----------------------------------------------
# Returns a list of the Top5 Searched terms.

my (@output,$db,$sth);

$db = $DB->table('SearchLog');
$db->select_options ('ORDER BY HitCount DESC', 'LIMIT 5');
$sth = $db->select;

while (my $row = $sth->fetchrow_hashref) {
push @output, qq~<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a>~;
}

return $#output > -1 ? join('-', @output) || 'No terms yet!';

}
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] top 5 search terms global In reply to
I have tried several different things and no luck..

The closest one I could come up with was:

sub {
my ($output,$db,$sth);
my $db = $DB->table('SearchLog');
$db->select_options ('ORDER BY HitCount DESC', 'LIMIT 5');
$sth = $db->select;

while ($row = $sth->fetchrow_hashref) {
$output .= qq~<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a>~;
}
return $output > -1 ? join('-', $output) || 'No terms yet!';

}


Can someone give me a hand here please..Mad
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] top 5 search terms global In reply to
Found it :)

Ugh it was so obvious too Blush.

Change || to :

Last edited by:

RedRum: Mar 12, 2002, 1:45 AM
Quote Reply
Re: [RedRum] top 5 search terms global In reply to
Thanks

still not working..

getting error: Global symbol "$row" requires explicit package name at (eval 9) line 8.
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] top 5 search terms global In reply to
Notice in the original it is:

while (my $row ...
Quote Reply
Re: [RedRum] top 5 search terms global In reply to
thanks

that fixed it
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] top 5 search terms global In reply to
Hi, I've been searching the forum for an answer but I'm stuck. I made a global by copy and pasting the 'Top 5 search terms' global and called it top_search_terms.

When I include it on a page (i.e. home.html template) I use this code:
Code:
<%top_search_terms%>


When I use 'build all' and check if it works I get this message on the spot where I put up the code: Unable to compile 'top_search_terms':

I just bought the script and the install and so went great, when I try another global (i.e. time) it works great... but this global just doesn't seem to work.

I hope some more experienced user can give me a tip or tell me how to get this working!

Thanks in advance,
Rik
Quote Reply
Re: [waxxie] top 5 search terms global In reply to
If you cut and pasted the global, make sure you did so, including the line breaks (long lines get into trouble), and that the first line:

sub {

contains only those 5 characters 'sub {' nothing else, including trailing spaces.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] top 5 search terms global In reply to
Thanks for your reply Pugdog,

I checked it but everything seems to be correct...

Code:


sub {

my (@output,$db,$sth);

$db = $DB->table('SearchLog');
$db->select_options ('ORDER BY HitCount DESC', 'LIMIT 5');
$sth = $db->select;

while (my $row = $sth->fetchrow_hashref) {
push @output, qq~<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a>~;
}
return $#output > -1 ? join('-', @output) || 'No terms yet!';

}


I also installed the 'SearchLogger' plug-in which works good... very weird I can't get that global to work.

Last edited by:

waxxie: May 20, 2003, 9:28 AM
Quote Reply
Re: [waxxie] top 5 search terms global In reply to
Is there no other error message?
Quote Reply
Re: [Paul] top 5 search terms global In reply to
No, it doesn't state anything after the ':'... just
Quote:
Unable to compile 'top_search_terms':
Quote Reply
Re: [waxxie] top 5 search terms global In reply to
Thanks all, I used another global for this purpose and that one worked...

Regards, Rik
Quote Reply
Re: [waxxie] top 5 search terms global In reply to
Hi, Rik;

What was the global you used to get the top 5 search terms?

I've had the same problem.Tongue
Quote Reply
Re: [webslicer] top 5 search terms global In reply to
I see the problem now.

Change:

||

to

:
Quote Reply
Re: [webslicer] top 5 search terms global In reply to
Hi webslicer, I picked it up somewhere on the forum but can't find it anymore :P

Here it is, I copied it from my global section:

Code:
sub { my $db = $DB->table('SearchLog');
my $x = 5;
my $output;
$db->select_options("ORDER BY HitCount DESC", "LIMIT $x");
my $sth = $db->select('Term');




while (my $res = $sth->fetchrow_hashref) {
$output .= qq|<a href="$CFG->{db_cgi_url}/search.cgi?query=$res->{Term}">$res->{Term}</a><br>|;}




return $output;

}


Regards, Rik
Quote Reply
Re: [waxxie] top 5 search terms global In reply to
I don't have this table called "SearchLog" in the mysql database. I am using linksql 2.1.2
Quote Reply
Re: [gundamz] top 5 search terms global In reply to
You need the searchlogger free plugin. It is available at no charge, installs easily and quickly.

Go to the links admin - plugins - and search for the script.
Quote Reply
Re: [gundamz] top 5 search terms global In reply to
If it's the advanced logger, you'll have to search the forums. I made a whole bunch of mods to the original program, but posted it in the forum about 2 years ago, not the plugins area. There are a few threads about it.

see here http://www.gossamer-threads.com/...orum.cgi?post=175351


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] top 5 search terms global In reply to
Hi

I am using G Link 3.0.4

I made the Global:
top_search_terms

And in the search_results.html template, I added:
<%top_search_terms%>

I rebuild, and made a search, and the following error es showing:

A fatal error has occured:

GT::SQL (1816): File '/home/myweb.com/cgi/admin/defs/glinks_SearchLog.def' does not exist or the permissions are set incorrectly at (eval 40) line 5.

Please enable debugging in setup for more details.


What is missing?


Thanks
Quote Reply
Re: [tenoch] top 5 search terms global In reply to
You have to install the search logger for it to work. The plugin is available from the download area.

I'll have the updated version, my "advanced" version available along with the other plugins I'm fixing up.

It gives you some extra options on the search page, and lets you plug in several "top" keys. The major difference between my version and the one GT released, is that I track daily as well as total searches.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] top 5 search terms global In reply to
Thank You pugdog

Where can I download your advanced version?

thanks
Quote Reply
Re: [tenoch] top 5 search terms global In reply to
Hi,

Sorry for the delay here.

I'm not sure where it can be downloaded <G>

I have to maybe upload the current GL3 version, although I sort of remember doing that before the holidays.

I haven't changed it since before thanksgiving.

I'll make sure it's available from somewhere today or tomorrow.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [katabd] top 5 search terms global In reply to
What code and tag works with Gossamer Links 3.3.0?
http://www.hopeforyou.com

Quote Reply
Re: [HopeForYou] top 5 search terms global In reply to
You REALLY should check out ULTRAGlobals. Its got the answer to pretty much all the questions you've just asked.

Last_Searched_Words()
Top_Search_Words()

Its linked in my signature, if you don't alread have it.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!