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

How to set default search for substring=1 ????

Quote Reply
How to set default search for substring=1 ????
I don't why , my default search
cannot search the substring word,
etc:
i search "abc" just have "abc" word,
cannot have "abcd" or "abc????" word.

please help me to set the default substring to substring=1.
Quote Reply
Re: How to set default search for substring=1 ???? In reply to
This is _VERY_ confusing, and I just went through it.

The form to search.cgi _should_ pass a 'substring' parameter either as a radio user-select option, or a hidden 'default' option.

If it doesn't, you can use:

(! defined $in->param('substring')) ? ($substring = 1) : ( Wink;

To default to "yes, search substrings" or

(! defined $in->param('substring')) ? ($substring = 0) : ( Wink;

to default to "no, search substrings".

If $in->param('substring') _is_ defined, you've passed in either a 1 or a 0 and you need to process it! If it's NOT defined, you can set your default by the above.

If you _DID_ pass in a value, as a radio or hidden field, you need to process it -- but it it does a 'flip-flop' in logic.

In the templates, you want to use "substring=1" for "yes, search substrings" or "substring=0" for "no, don't search substrings"

_BUT_ in the search.cig this is changed at the top, when the 'substring' input is altered to 'ww'.

Code:
($in->param('substring')) ? ($ww = 0) : ($ww = 1);

"ww" is "whole word" which is the logical OPPOSIT of "substring" (if _not_ substring then ww, if substring then _not_ ww)

So, to search on PARTIAL WORDS (substrings) you need to pass 'substring=1' to the search.cgi then set 'ww'= 0 for "no, don't search on whole words"

This is actually clearer in some respects when designing templates, but creates a "double negative" problem in program logic.

I changed several sites over to using 'ww' and got rid of 'substring' as the passed parameter.

I also added:

Code:
($in->param('ww')) ? ($ww = 1) : ($ww = 0);

To the list to process 'ww' if passed in. NOTE: if $in->param('ww') is 1, then $ww=1, if it's 0 then $ww=0.

This is the _opposite_ of 'substring'


******
****** If any of this is wrong, let me know so I can edit!
****** I'd like to add this to the FAQ since it's an endless source of confusion
******
Quote Reply
Re: How to set default search for substring=1 ???? In reply to
Edit search.cgi:

If you want to default to substrings on, use:

(defined $in->param('substring')) ? ($substring = 1) : ($substring = 0);

If you want to default to off, leave as is.

Cheers,

Alex
Quote Reply
Re: How to set default search for substring=1 ???? In reply to
Didn't make it all the way through, got too confusing. =)

What I would do is, if you want to default to search substrings:

$substring = defined $in->param('substring') ? $in->param('substring') : 1;

if you don't want to default, change the 1 to a 0. What the above says is, if we've been passed in substring=something, lets set subtring to that, otherwise let's use 1.

Cheers,

Alex