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

top 5 search terms

Quote Reply
top 5 search terms
I've been looking for a way to adjust the search pages to show a variety of stats from the search database.

Modifying a 'top5' routine that was written before, you can generate a bunch of variables that hold a list of data.

I _don't_ use SSI, so i have no way to make that sort of version work.

But, here is a list of things to do to add a <%top5%> tag to any of the templates that use HTML_Templates.pm -- including search.cgi so you can put a suggested list in that file.

First:

Add:
Code:
use CGI ();
to the top of the HTML_Templates.pm 'use' list, and

<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:</font><HR><pre>
use Links: Smile I've created a few different routines, and can test/debug each of them and use them separately.
Quote Reply
Re: top 5 search terms In reply to
I just added a bunch of stuff to my search page.

You can check it out here
http://www.postcards.com/...Postcards/search.cgi

These are cgi generated, and yank the information from the database. The speed difference after indexing the "Count" and "Last_Hit" fields was STAGGERING!

I know there have to be better ways of figuring out the dates -- doing date arithmetic -- and things such as the "top_today" and eventually the "top_yesterday" could be coded more elegantly to use less system resources.

By using more tables, and keeping better tabs of what was being looked at, you could generate stats that could be inserted into a side-bar on each build, or into any cgi generated page (or even SSI).


Quote Reply
Re: top 5 search terms In reply to
Software error:
Can't locate object method "new" via package "Links::BSQL" at Links/HTML_Templates.pm line 749.
Quote Reply
Re: top 5 search terms In reply to
Code:
Can't locate object method "new" via package "Links::BSQL" at Links/HTML_Templates.pm line 749.

You need to make the BSQL 'DBSQL' and you need to do the same in the use DBSQL line.

The smiley faces are a real pain... and should not appear in the code blocks, but they do.

I've also figured out how to count daily search term hits, and keep a running total for each day, and I'm working on a way to log the results, so that once a day is over, the program looks to see if the summary exists, if it does, it uses that, if not it calculates it, then stores the summary so that future searches don't have to re-generate it.

This solved a much larger problem for me, and has implications for my "Top 10" links, "Top Today" and "Yesterday" etc. Look for the release soon. If anyone _needs_ this now in beta code, drop me an email. You are on your own for how to install it, but if you want the beta code, you should know how to do that. Once it's all done, the subroutines could be cloned and modified to do just about any sort of tracking and "top" lists you would want. It's just a munge from jump.cgi and search.cgi but it's a useful one!


Quote Reply
Re: top 5 search terms In reply to
Ok resolved Problem....

He works perfectly...

Pugdog some has sort things out of showing in the result pages the last 5 words sought in the database?

I have a mod that shows me that but it shows many and in a file separate CGI.. I would like to show in the template of serch results and only the last 5.. does he have some way of doing this?

Does any one have some idea?
Quote Reply
Re: top 5 search terms In reply to
It's the language barrier -- I'm not sure what you are asking.

Quote Reply
Re: top 5 search terms In reply to
do I want to know if he has some it sorts things out of showing the last 5 words searched in a template, as she does with top 5, only that not showing the 5 more sought and yes the last ones 5 sought, did she understand?
Quote Reply
Re: top 5 search terms In reply to
I'm still not sure what you are asking.

This mod will show the last 5 search terms, (or any number you change it to) and it uses templates.

If you check out:

http://postcards.com/...Postcards/search.cgi

This shows the most-often searched words, the most recently searched words, the most searched words of today ... and can easily be set to show most common searches for yesterday, or any date range.

These routines return a <%variable%> that can be included in any template that uses HTML_Templates.pm, since it's passed through the %GLOBALS hash.

Quote Reply
Re: top 5 search terms In reply to
How do I do to show the last 5 search terms?
Quote Reply
Re: top 5 search terms In reply to
Ah... I was reading it all wrong!

All you do is change the:

sb => 'Count',

To

sb => 'Last_Hit',


sb stands for "sort by" as a parameter passed to the search.

If you use this is search.cgi or page.cgi you should see the changes every time you enter a keyword.

Try it on my site... search for something, then reload the search page, and you'll see your search is the top of the "most recent" list.

Quote Reply
Re: top 5 search terms In reply to
Hi Pugdog
I instilled your mod top 5 search terms few days ago.
I have a small problem, someone is cheating..
They are searching for their URl 10's of times so it will always display on my home page and search result page...

Is there a way to prevent diplaying the URL or anything that starts with http:// and only display actuall keywords?

Regards
Christa


Quote Reply
Re: top 5 search terms In reply to
Wow.... I did the same thing by editing out "sex" words.

The fix is ugly... <G> I've thought of a better way, but never did it:

Code:
my $results = $search->prepare (" SELECT *
FROM Search_Log_Daily
Where Term NOT RLIKE 'sex' AND Term NOT LIKE '%porn%'
ORDER BY Count DESC
LIMIT 11 ");
Just add, an:

AND Term NOT LIKE '%http:%' to the string.

You can also do something like this, that may be over all better:

AND Char_Length(Term) > 12

There are 11 characters in http://www.

If someone is trying to get around that, you can probably also eliminate any string with a '.'

Since that is a reserved character, I'm not sure how that would work exactly, but

AND Term NOT LIKE '%\.%'

Might do it.

Any ONE of the above is a reasonable solution. More than that is unnecessary.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: top 5 search terms In reply to
I am running in a problem:
My sub yop5 looks like

sub Top5 {
# -----------------------------------------------
# Returns a list of the Top5 Searched terms.
#
my $in = new CGI;
my $Search = new Links::DBSQL $LINKS{admin_root_path} . "/defs/Search_Log.def";
# Let's get a list of the Top 7 terms ordered by number of times someone
# has Searched on them.
my $results = $Search->query ( { Term => '*', sb => 'Count', so => 'DESC', mh => 7 } );
my $results = $search->prepare (" SELECT * FROM Search_Log_Daily Where Term NOT RLIKE 'sex' AND Term NOT LIKE '%http%' ORDER BY Count DESC LIMIT 11 ");
my $output = '';
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;
}

I think that is correct but when I call and page that uses the tag <%top5%> I get an error message software error
error in HTML_Templates.pm.

please take a look at the "sub" and advise.
regards

Quote Reply
Re: top 5 search terms In reply to
What's the error message exactly?

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: top 5 search terms In reply to
Upon calling any document that conatins the tag (search.cgi in this case)I will get:

[Thu Nov 9 17:22:53 2000] HTML_Templates.pm: Compilation failed in require at search.cgi line 34. BEGIN failed--compilation aborted at search.cgi line 34.

Thanks

Quote Reply
Re: top 5 search terms In reply to
>> my $results = $search->

You didn't give the whole error message.

You are using $Search and you tried to use $search without defining it first.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: top 5 search terms In reply to
The exact message I got is:
Not an ARRAY reference at admin/Links/HTML_Templates.pm line 728.

Quote Reply
Re: top 5 search terms In reply to
And what is line 728 in HTML_Templates.pm??

_USE_ the error messages to find the problem.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: top 5 search terms In reply to
Hello everyone!

This mod is awesome! Good job Pugdog! My only question is, how can I clear my current keywords because usual the top 5 terms don't change that much and I want to clear them like every month or something. Thanks for God bless!


<><------------><>
Daniel
http://www.christian-search.net
<><------------><>
Quote Reply
Re: top 5 search terms In reply to
Thanks :)

Do you mean clear out all your search terms? Or just old ones?

If you want to keep your search terms, so you maintain an all-time "high" list, there isn't much you can do, since the terms are agregated in the Search_Log table, so if you have 39,000 entries in that table, there are 39,000 different terms, not 39,000 searches (following?). If the table kept a list of all the searches, you could delete the x-number of oldest searches, and "freshen" the list a bit. This _will_not_ work with the current implementation.

In the Search_Log_Daily, you can trim that file by

DELETE from Search_Log_Daily Where TDate > 2000-09-30

or similar. That will reset the various sub tables.

If you delete the Search_Log file, your site will re-set, in effect, and you will be starting your "searches" over from '0'. For an established site, that might look funny.

I'll think about this for a little and see if I can come up with a way to make a sort of 'rolling' "top" searches.

That could probably be done by reading the Search_Log_Daily table, going back how ever far you wanted to, then generating a Top_5 or Top_10 list from that, and storing it in a file, and just including that file in.

You could update that file once a month, or whenever it struck you, but you'd still be tracking the all-time top searches, and keeping a daily log.

That may be the best... let me see if I can get that to work :)



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: top 5 search terms In reply to
Hi, how I can ban unwanted words (like sex, porn, [bleep!]...)

JS