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

Adding New Search Fields?

Quote Reply
Adding New Search Fields?
Hi,

Can anyone tell me if its possible to add new search fields to linksSQL, and if so what would be involved.

For example, if I wanted to add a selection of pull down menus that the user could select from, and whatever they selected would narrow down the search. Or checkboxes, radio buttons etc.

Cheers,
Regan.
Quote Reply
Re: [ryel01] Adding New Search Fields? In reply to
I think it is just a matter of editing the search templates and making sure the fields have the same name as the column.
Quote Reply
Re: [PaulWilson] Adding New Search Fields? In reply to
Hi Paul,

So no hacking of search scripts needed at all? I guess if it's in the form tags it will just get passed in with the submit to the search script?

Cheers,
regan.

Quote Reply
Re: [ryel01] Adding New Search Fields? In reply to
Yes, since the 1.1x version, (maybe before?) there was a way to use the column name a search field.

You can search the forums for some ideas on how to do it.

Basically it's adding a field to the template in the search box. No script changes should have to be made.

To use the drop down and select boxes, and such -- complex searches should work, as long as the form presents the data in the proper key=value pairs (input/value) format.

I'd have to defer to Alex on the specifics of it, since the search module is somewhat of a black box... search.cgi has progressively gotten smaller, and the search routines have gotten larger with each update :)

I'm still hoping to have some new "fresh" sites up and running this week.



PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [ryel01] Adding New Search Fields? In reply to
Hi,

No changes to code are required. You can call:

search.cgi?ColumnName=x

to search on a column. You can also use it to "filter" results. So if you do:

search.cgi?query=x&ColumnName=y

it will do a regular search on 'x', and then filter out only those results where ColumnName=y. A simple example would be:

search.cgi?query=cars&isCool=Yes

to only find cool links about cars.

Hope this helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Adding New Search Fields? In reply to
Hi,

Well that's easy:). Ehm 1 question ...

If u do search.cgi?Title= (so it's empty) it will display all
records
. But what to change that at least 1 character must be given? (not protected with javascript:))....

Allready thanks.

Regards Startpoint.
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
Hi,

You can change admin/Links/Search.pm line 46

if (defined $args->{$_} or defined $args->{$_ . '-lt'} or defined $args->{$_ . '-gt'}) {

to:

if ((defined $args->{$_} and length $args->{$_}) or
(defined $args->{"$_-lt"} and length $args->{"$_-lt"}) or
(defined $args->{"$_-gt"} and length $args->{"$_-gt"}))
{

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Adding New Search Fields? In reply to
Hi Alex,

U wrote:
You can change admin/Links/Search.pm line 46 ..

This must be line 48 (?) and admin/Links/User/Search.pm i quess?

At line 48 i have:
if (defined $args->{$_}) {

and i tried:
if (defined $args->{$_} and length $args->{$_}) {

But it still display all links if the search_field is empty?

Any ideas?

Regards Startpoint.
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
Hi,

What are you passing into the search.cgi?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Adding New Search Fields? In reply to
Hi Alex,

I do a search on Title....

Regards startpoint..
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
So going to

search.cgi?Title=

causes it to load all records? Hmm, that shouldn't happen if you made the change I described.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Adding New Search Fields? In reply to
Hi,

Can u check your changes u described, because i hadn't that file in your location and the line nr. was also different. See my message above.

Allready thanks.

Regards startpoint.
Quote Reply
Re: [Alex] Adding New Search Fields? In reply to
Hi Alex,

U wrote:

if ((defined $args->{$_} and length $args->{$_}) or
(defined $args->{"$_-lt"} and length $args->{"$_-lt"}) or
(defined $args->{"$_-gt"} and length $args->{"$_-gt"}))
{

I quess it has to be:

if ((defined $args->{$_} and length $args->{$_}) and
(defined $args->{"$_-lt"} and length $args->{"$_-lt"}) and
(defined $args->{"$_-gt"} and length $args->{"$_-gt"}))
{

Right?



Somehow it still not 100% right because if i have arguments like:

example 1. search.cgi?query=&Link_ok=Tes

It will display a part of a page (so when query is empty)

and if i do:

example 2. search.cgi?query=aa&Link_ok=Tes

So when the query is 2 letters it will display "nothing has been found" but actually u have to enter min. 3 letters to do the real search.


U got any idea's how to solve it? What i want is that it display u have to enter min. 3 letters to do a search...


Cheers...

Last edited by:

startpoint: Jan 23, 2003, 3:12 AM
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
Hi,

Well i think the code Alex provided with 'or' (instead of and) was ok, but because i use more than 1 argument it still pass with a empty search. So the code have to be a bit different.

1. Title must not be empty and bigger then 2 characters

2. I will use more arguments then 1.

When i only use Title=someting it works good i quess, but with more arguments the code isn't right...

I don't know the solution yet.



So basically i wanna do:

search.cgi?Title=mac&Link_ok=Yes&print=no&other=1

Then is will display records if it will be found, but with search:

search.cgi?Title=&Link_ok=Yes&print=no&other=1

so Title = empty (or < 3 characters) it must not display a record and it will display the search.html template...

Hope someone can help me with this.



Allready thanks.

Last edited by:

startpoint: Jan 23, 2003, 5:32 AM
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
If you Index Internal you would probably not find anything (is that what you want?)

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Adding New Search Fields? In reply to
Hi Klaus,

Doesn't have anything to do with the index. It's just that there need to be a check it a searchfield is bigger then x characters else don't search.

But thanks for the reply.
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
Right - but by indexing Internal you get just that min 3 chrs to make a search...

Might still not be what you want though

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Adding New Search Fields? In reply to
Hi,

Well basically is that what i want, the but i want to search on 1 field in the database not with query=...

Thanks again for your reply.
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
Have you tried:

search.cgi?query=&Title=&Link_ok=Yes&print=no&other=1

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Adding New Search Fields? In reply to
Lol that's a smart idea, but if query = empty it will still go to the other routine and still display all records. It didn't work.

I will now debug the code and try to figure it out.

Thanks again.
Quote Reply
Re: [startpoint] Adding New Search Fields? In reply to
I couldn't find a good solution so i hardcoded it in search.pm

if (length $args->{'Title'} > 2)
{
# Otherwise, if we pass in a field name, we can search on that too.
foreach (keys %{$db->cols}) {
if ((defined $args->{$_} and length $args->{$_}) or
(defined $args->{"$_-lt"} and length $args->{"$_-lt"}) or
(defined $args->{"$_-gt"} and length $args->{"$_-gt"}))
{
$IN->param('isValidated', ['Yes']);
return search();
}
}
}


Now it's working and because i don't use search atm for anything else it's ok. Not a nice way but ok.