Gossamer Forum
Home : Products : Gossamer Links : Discussions :

If <%searchterm%> in list then... else...

Quote Reply
If <%searchterm%> in list then... else...
Hi,

I thought I already posted this, but must have made a mistake Crazy

Anyway, althought I've had GT products since 1998, I still have trouble editing and modifying them (my fault completely!). Basically I'm looking for some help with LinksSQL 2.0.5.

I want Links to check each search_term against a special list of keywords. If there is a match then "A" happens, if not then "B" happens. The list of special keywords will be made by me and probably just uploaded as a text file or whatever you suggest.

I'm sure this is easy enough for "oldies" like Pugdog and Eliot!

Regards,

JeffB.
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
Anyone got any ideas - I thought it would be fairly simple Unsure
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
Hello, Jeff.

The logic you would have to apply is the following:

1) Create a table that stores the "special keywords". Call the table something like Links_SearchTerms with the following attributes:

Quote:

SearchTermID (PRI, AUTO-INCREMENT)
SearchTerms (TEXT, NOT NULL)


2) Create a global that uses the following SQL Statement:

Quote:

SELECT SearchTerm
FROM Links_SearchTerms
WHERE (SearchTerm LIKE '%$query%')


In this global, return the total number of matches. $query is the var for the keywords entered.

There are quite a few examples of creating globals in this forum and some are linked in the Resources section.

3) Then in your search templates, you can reference the global and set up some conditional statements.

Like:

Quote:

<%if related_links gt 0>
DO A
<%else%>
DO B
<%endif%>

========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
In your search results template you can put:

<%if query eq "keyword"%>
.. do this
<%else%>
.. do this
<%endif%>

That does an exact match. If you want to do something more complicated, you would need to use a global. Add:

keyword_case =>

Code:
sub {
my $tags = shift;
my $query = $tags->{query};
if ($query =~ /keyword1|keyword2|keyword3|keyword4|.../) {
return "some html here that it matched";
}
else {
return "no match";
}
}

You could then put <%keyword_case%> in your search_results template.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] If <%searchterm%> in list then... else... In reply to
Alex (and Eliot)

Thanks for your solutions. Alex: Your solution looks great, but I would like it to check a file of "special" keywords, rather than a list within the global.

What do I need to alter in your code above to do this?

Thanks

JeffB.
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
any further ideas?

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
I could really do with this kind of modification. The framework is above but I need more specific instructions. Any help would be great Cool

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
What format is the file in? Would an array loop not be better? Unsure

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: [Andy] If <%searchterm%> in list then... else... In reply to
Hi,

Thanks for your reply. It doesn't really matter what kind of file the list of keywords is in. The reason why I didn't like Alex's suggestion above is because we might have over 500 keywords and that would make a very large array within the global.

Here is an overview of what I need...

1. User searches for a celebrity, i.e. Cameron Diaz

2. Links checks the keyword ("Cameron Diaz") against a list of celebrity names. These names will represent all the celebrities we have forums for. If there is a match between our list and the user's keyword, then Links will display "Visit our Cameron Diaz forum" otherwise it will just display "Visit our Fan's Forum".

I hope this makes things clearer. I'm sure that this can't be very hard?

JeffB

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
>>
The reason why I didn't like Alex's suggestion above is because we might have over 500 keywords and that would make a very large array within the global.
<<

How about listing the words in a file and reading the file.
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
Yeah, exactly what I was thinking Paul. Maybe something like;

Code:
sub {
my $tags = shift;
my $query = $tags->{query};
open(FILE, "/path/to/file/with/words/in.txt") || die "Unable to read file. Reason: $!";
while (<FILE>) {
if ($query =~ /$_/) {
return "some html here that it matched";
last;
} else {
return "no match";
}

close(FILE);

}

No guaranteing it will work. The file format needs to be something like;

keyword::some html or whatever here (use whatever divider you want, and then use the split() command to cut it up).

Hope that helps.

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: [Andy] If <%searchterm%> in list then... else... In reply to
Well that won't work because you aren't going to get past the first line of the file before it returns....and you'll have an open filehandle.

Last edited by:

Paul: May 24, 2002, 5:38 AM
Quote Reply
Re: [Paul] If <%searchterm%> in list then... else... In reply to
Any further ideas on this? Do you think I should re-post this question in the Mods & Customizations forum? I could really do with a solution to this as it's been a couple of months since I first asked about it. Any further ideas on would be great! Cool

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
You could either create a new table and select the words from it, or upload them in a text file - depending on the number of words/searches will depend on which option you should choose.
Quote Reply
Re: [Paul] If <%searchterm%> in list then... else... In reply to
Nice avatar Paul Sly

I will probably have around 500 terms, so which one do you suggest? Also, can you give me some pointers on the code I need to use? I'll send you an Amazon gift voucher if you can help me Wink

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
Hi,
Please tell me what you want to display when match the term or not match.
I suggest that plugin hook in the search function should be sufficient.

Regards,

Beck
Quote Reply
Re: [Beck] If <%searchterm%> in list then... else... In reply to
If someone searches for a celebrity and their name appears in my special list then I want links to say "Click here to view "Celebrity Name" photo gallery" otherwise if there is no match it should return "View photo galleries".

JeffB
GT customer for 6 years (and counting!)
Quote Reply
Re: [jeffb] If <%searchterm%> in list then... else... In reply to
Hopeful bump Wink

Anyone?

JeffB
GT customer for 6 years (and counting!)