Gossamer Forum
Quote Reply
Stop Words Global...
I searched the forums for this, but couldn't find anything...

Does anyone know of a global that you could use if someone enters a stop word or two few characters (just a letter or number) that would display a error that the word was too common, or too short, etc?

My idea was something like:

Create a global called stopword_error:
Code:
sub {

# Set query variable to actual query
my $query = $IN->param('query');
my $error = '';

# Determine if query is a stop word
if $query = blahblahblah {
$error = "The word searched is too common...";
}

# Determine if the query is too short
if $query = blahblahblah {
$error = "The word searched is too short...";
}

# Return the error
return $error;

}

Then in your search.html template, you could do:

<%if error%>

<%if stopword_error%>
<p><font color="red"><b><%stopword_error%></b></font></p>
<%else%>
<p><font color="red"><b><%error%></b></font></p>
<%endif%>

<%endif%>


Being so new to perl, I'm not sure how to make this work. Does anyone have any ideas on this?

Sean

Last edited by:

SeanP: Apr 26, 2002, 10:28 AM
Quote Reply
Re: [SeanP] Stop Words Global... In reply to
Ideally you'd want this as a plugin so it would not even do the search if it was a custom stop word.

However, a global will work and you are on the right track. How about something like:

format_error =>

Code:
sub {
my $tags = shift;
my $query = $IN->param('query');
my %stopwords = map { $_ => 1 } qw/a stop word list goes here they should be space separated/;
if (length $query < 3) {
return "Your query is to short.";
}
if (exists $stopwords{$query}) {
return "The word '$query' is a stopword.";
}
return $tags->{error}; # Display default error
}


and then do:

<%if error%>
Error: <%format_error%>
<%endif%>

Hope this helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Stop Words Global... In reply to
Thanks!

Actually, I wanted to determine whether is was a stop word from the stop word list set in the search settings. That way, it wouldn't search anyway, it would just customize the error.

Sean
Quote Reply
Re: [Alex] Stop Words Global... In reply to
Is it possible to just pull in the stop words list within the global from /admin/GT/SQL/Search/Base/Common.pm by doing a:

Code:
use GT::SQL::Search::Base::Common;

?

Sean
Quote Reply
Re: [SeanP] Stop Words Global... In reply to
Sorry to butt in here, but I am just wondering, would a stop word or query filter of some sort improve performance by not allowing searches on common words? For example you could filter out single digit letters, swear words etc.

This would also prevent prankster search queries showing up in the search stats.
Quote Reply
Re: [sooke] Stop Words Global... In reply to
In Reply To:
Sorry to butt in here, but I am just wondering, would a stop word or query filter of some sort improve performance by not allowing searches on common words? For example you could filter out single digit letters, swear words etc.

This would also prevent prankster search queries showing up in the search stats.

There is already a stop word and single digit filter built into Links SQL. The stop words are found in /admin/GT/SQL/Search/Base/Common.pm (line 24). By default a query must be 3 characters in length. This is set in /admin/GT/SQL/Search/Base/Search.pm (line 56). You can change the values of both, but you will have to reindex.

Sean
Quote Reply
Re: [SeanP] Stop Words Global... In reply to
Thanks Sean.

Now that you mention it, the 3 minimum does ring a bell. I am going to check out the settings in the pm files. Thanks for the line numbers too!
Quote Reply
Re: [Alex] Stop Words Global... In reply to
If I included Common.pm to the global, what is the syntax for using the $STOPWORDS variable?

Sean

Last edited by:

SeanP: May 1, 2002, 9:52 AM
Quote Reply
Re: [Alex] Stop Words Global... In reply to
Does anyone know how to reference a variable from a included file?

Sean
Quote Reply
Re: [SeanP] Stop Words Global... In reply to
Here's the final:

Create global called "error_formatted" with the following code:
Code:
sub {
require GT::SQL::Search::Base::Common;
my $tags = shift;
my $query = $IN->param('query');

if (exists $STOPWORDS->{$query}) {
return "The word '$query' is too common.";
}
if (length $query < 3) {
return "Your query is too short.";
}
return $tags->{error}; # Display default error
}

Then, edit your search.html template and replace:

Code:
<%if error%>
<%error%>
<%endif%>

with:

Code:
<%if error%>
<%error_formatted%>
<%endif%>

That's it!

Sean
Quote Reply
Re: [SeanP] Stop Words Global... In reply to
Actually, I found problems with that one. This one seems to work properly (Thanks Paul!):

Code:
sub {
require GT::SQL::Search::Base::Common;
my $STOPWORDS = $GT::SQL::Search::Base::Common::STOPWORDS;
my $tags = shift;
my $query = $IN->param('query');

if (exists $STOPWORDS->{$query}) {
return "The word '$query' is too common.";
}
if (length $query < 3) {
return "Your query is too short.";
}
return $tags->{error}; # Display default error
}

Sean
Quote Reply
Re: [SeanP] Stop Words Global... In reply to
Hi All,
Thanks for the global. I have a question.
How do I write a tag then for if no results on query?

I have an alternate search box that appears if there are no results based on if error

But I want to use the global here and then if they type and get the new formatted error message, I don't want the alternate search box to appear unless no results.

Any ideas?

THX!!
Quote Reply
Re: [SSmeredith] Stop Words Global... In reply to
That sounded a little complicated :)

Can you explain what exactly you mean?
Quote Reply
Re: [SSmeredith] Stop Words Global... In reply to
Where did you want this 'other box' to appear? ON the search.html page, if no results were found? If sdo, you may be able to just get away with using and 'if' tag to see if <%error%> is defined.

Hope that helps Smile

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!
Quote Reply
Re: Stop Words Global... In reply to
Hi Guys!

I've already got it working now with the alternate (I should say 3rd party ) search box.

See here:
http://constructionclub.com/cgi-bin/linkssql/search.cgi?d=1

The type in some silly word, you'll be prompted to try another search on the web. I used the error tags so -if error- show the other search box.

But now I want to use this global. But I don't want the user to see the other search box if the user types in a too short word or a word from the stop list, only if they don't get any results from the first...

Does that make sense?
Quote Reply
Re: [SSmeredith] Stop Words Global... In reply to
You would probably need a plugin, to do something like my SearchFeed_Results plugin, but instead of grabbing new results, it just passes along a variable, that you can wrap an 'if' tag around, as to only show if no results were found...

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!