Gossamer Forum
Home : Products : Links 2.0 : Discussions :

search for two-letter string

Quote Reply
search for two-letter string
Hello,

I could not find where I can specify the shortest length for search string. I remember I can do it somewhere...

I want users to search for two-letter words.

Your feedback is appreciated.
Quote Reply
Re: [long327] search for two-letter string In reply to
By default, two-letter words are the shortest allowed. Are you wanting to allow searching on ONLY two-letter words?

In search.cgi, change the < (less-than) to != (not-equals) to allow ONLY two-letter search terms. You should probably also work on an error message, and/or change the search box to a two-character field (size="2").

Code:


sub search {
# --------------------------------------------------------
# This routine does the actual search of the database.
#
my ($search_terms, $bool) = @_;
my ($regexp, @values, $grand_total, $match, $andmatch, $field, $or_match, %seen, $link, $tmp);
# Save the reg expressions to avoid rebuilding.
$or_match = $bool ne 'and';
if ($or_match) {
for (0 .. $#{$search_terms}) {
next if (length ${$search_terms}[$_] < 2); # Skip single letter words.
$tmp .= "m/\Q${$search_terms}[$_]\E/io ||";
}
}
else {
for (0 .. $#{$search_terms}) {
next if (length ${$search_terms}[$_] < 2); # Skip single letter words.
$tmp .= "m/\Q${$search_terms}[$_]\E/io &&";
}
}


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] search for two-letter string In reply to
Thank you Leonard !

If two-letter string is the shortest allowable query, my search seems to have problem returning two-letter matches.

The code you gave must be part of search.pm in Links/Users folder, right?
Quote Reply
Re: [long327] search for two-letter string In reply to
This forum is for links 2, flatfile database; are you using Links SQL?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] search for two-letter string In reply to
I am sorry, I posted in the wrong place.

Thank you.