Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Highlight search terms

Quote Reply
Highlight search terms
Hi,

Currently when searching you can get search terms bolded in Links - however when looking at a detailed page the bolding stops.

If I passed <%query%> in the URL to the Detailed page - could I then have search terms hightlighted?

Even better - a google toolbar highlight button type of solution...

Ideas?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Highlight search terms In reply to
I don't see why not. If you pass ?query=<%query%> to the details page, and then had something like this in the detailed page;

Code:
<%if query%><%New_Description%><%else%><%Description%>

Then create a new global, called 'New_Description'. Then put something like this into it;

Code:
sub {
my $tags = shift;
my $desc = $tags->{Description};
my $keyword = $tags->{Query};
my $desc =~ s,$query,<span style="background-color: #FFFF00">,g;
return $desc;
}

This code is untested, so it may, or may not work Wink

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!
Quote Reply
Re: [Andy] Highlight search terms In reply to
Thanks Andy - did not work as intended...

I tried with some javascript, which sort of works - but have two problems:

1. When highlighting the text it gets converted to lowercase

2. Can't remove the highlight again once a user clicks...(wanted to let a user click ahain and then the highlight is removed)

Here is the script:

Code:
<style type="text/css">
<!--
font.highlight {color: black; background: yellow}
-->
</style>

<script language="javascript">
function changetext() {
var rng = document.body.createTextRange();

if (wrd.value != '')
while (rng.findText(wrd.value) )
rng.pasteHTML('<font class=highlight>' + wrd.value + '</font>');
}
</script>

Then this to produce the button to highlight:

Code:
<p><input type=hidden name=wrd value="<%query%>"><input type=button value=Highlight! onclick='changetext()' id=button1 name=button1></p>


Any suggestions?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Highlight search terms In reply to
Hi,

Andy's version has the idea, it may just need a bit of tweaking.

to clear the highlighting, you'd request the page again, and bypass the highlighting. If it was just in the description/newdescription tags, you might be able to just update that text block with xml (don't know for sure), otherwise you'd need to call the display routine and turn it off.

I need something simple to do today, and I'll see if I can update detail_page.cgi to do this.

You might be able to do it by setting up a link to pass a new tag into the detail_page.cgi from the search_results page:

detail_page.cgi?...&highlight_desc=<%Description%>

When you get to the detail.html page, use the <%if%> to select <%highlight_desc%> vs <%Description%>

If you then refresh the page, calling it with just ID=nnnn the highlighting should go away. You won't be able to get it back <G> But that is what I want to see if it can be done by adding a tag/flag to detail_page.cgi.

I have too many versions of that script out with subtle behavioral differences, and it'stime to get one finalized (again).


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Highlight search terms In reply to
Hi Pugdog,

I like Andy's way - just could not make it work... the description does not show up at all..

I replaced $query with $keyword - but no luck

I'd like to have a link at the top of the page "Highlight Query" and the re-load the page with highlights - then when reloaded the link should change to "Remove hightlight"

Any suggestions? Andy?

Klaus

http://www.ameinfo.com

Last edited by:

klauslovgreen: Mar 7, 2003, 7:05 AM
Quote Reply
Re: [klauslovgreen] Highlight search terms In reply to
Try this:

Code:
sub {
my $query = $IN->param('query');
my $desc = $_[0]->{Description};
$desc =~ s|(\Q$query\E)|<b>$1</b>|sg;
return $desc;
}
Quote Reply
Re: [Paul] Highlight search terms In reply to
Hi Paul,

Yes works - except it is case sensitive... how can I get rid of that? It should return the same case - but right now it highlights ex. oracle but not Oracle...(query=oracle)

Also it does not work with more than one word..

ex. 'query=mobile handheld' - only if the two words happens to appear next to each other they will be highlighted.

Thanks in advance
Klaus

http://www.ameinfo.com

Last edited by:

klauslovgreen: Mar 7, 2003, 7:49 AM
Quote Reply
Re: [klauslovgreen] Highlight search terms In reply to
Change to;

$desc =~ s|(\Q$query\E)|<b>$1</b>|sgi;

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: [klauslovgreen] Highlight search terms In reply to
Whoops, I meant to add case sensitivity but forgot. Change the "sg" to "sig"

Regarding multiple words, try:

Code:
sub {
my @query = split /\s+/, $IN->param('query');
my $desc = $_[0]->{Description};
for (@query) {
$desc =~ s|(\Q$_\E)|<b>$1</b>|sig;
}
return $desc;
}

Last edited by:

Paul: Mar 7, 2003, 8:07 AM
Quote Reply
Re: [Paul] Highlight search terms In reply to
thanks a lot guys :-)


Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Highlight search terms In reply to
I went ahead and played with it any way.

detail_page.cgi can pass through parameters, such as Query=<%query%>

in detail.html you have to add a few switches:

Code:
<%if Query%>
<%highlight ($Query, $Description)%>
<%highlight_text%>
<HR>
<A href=<%db_cgi_url%>/detail_page.cgi?ID=<%ID%><%if Query%>&query=<%Query%><%endif%>>Reload page without highlighting</A>
<%else%>
<%if query%><%highlight ($query, '2x2')%><%endif%>
<%Description%>
<HR>
<A href=<%db_cgi_url%>/detail_page.cgi?ID=<%ID%><%if query%>&Query=<%query%><%endif%>>Reload page with highlighting</A>
<%endif%>


in link.html you pass in the term, like this:

Code:
<%if detailed_url%>
&nbsp;<a href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%><%if query%>&Query=<%query%><%endif%>">Details</a>
<%endif%>


If there is no "query" (not on a search page) it will just be ignored, and you'll get a regular page view.

Then, you add a global, a modified version of pauls fix up:

Code:
sub {
my ($query_term,$highlight_text) = @_;
if ($highlight_text eq '2x2') {
$query_term =~ s|\s+|%20|sig;
return ({query => $query_term});
}
$query_term =~ s|%20|\s|sig;
my @query = split /\s+/, $query_term;
my $desc = $highlight_text;
for (@query) {
$desc =~ s|(\Q$_\E)|<b>$1</b>|sig;
}
$query_term =~ s|\s+|%20|sig;
return ({highlight_text=>$desc, query=>$query_term, Query=>$query_term} );
}



The trick was making multiple words stick between refreshes.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Highlight search terms In reply to
Hi Pugdog,

Thanks - looks nice!

Got it working - thanks a lot

Klaus

http://www.ameinfo.com

Last edited by:

klauslovgreen: Mar 7, 2003, 11:30 PM
Quote Reply
Re: [pugdog] Highlight search terms In reply to
>>>in detail.html you have to add a few switches: <<<

Its detailed.html Wink

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: [klauslovgreen] Highlight search terms In reply to
Quote:
Thanks - looks nice!

So does my code mixed in the middle Wink
Quote Reply
Re: [Paul] Highlight search terms In reply to
Pugdog gave you credit for your code Wink

>>>, a modified version of pauls fix up: <<<

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: [pugdog] Highlight search terms In reply to
Quote:
$query_term =~ s|\s+|%20|sig;

The i and s in that regex are redundant.

Also this won't do what you think it will:

Quote:
$query_term =~ s|%20|\s|sig;

It should be:

Code:
$query_term =~ s|%20| |g;

Last edited by:

Paul: Mar 8, 2003, 2:52 AM
Post deleted by klauslovgreen In reply to
Quote Reply
Re: [Paul] Highlight search terms In reply to
Paul,

I don't like regex's and was just following your lead ;)

If you can fix it up, I'm sure everyone will appreciate it.

This is not clean, neat, tweaked code, it was just a quick hack to solve a specific problem. I'd like to actually get this generalized to allow highlighting of any code/text passed in with any term. This would allow a glossary, or other similar non-search feature possible. As you can see here, it's not as simple as it seems. There are problems with the little things like spaces, line breaks, etc.

It probably should also have a flag to indicate highlight or unhighlight as well, rather than relying on a toggle system.

Thanks,


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Highlight search terms In reply to
Hi Pugdog,

Yes it needed a little work - but I got it working the way I wanted - thanks for your help everyone..

Klaus

http://www.ameinfo.com
Quote Reply
Re: [pugdog] Highlight search terms In reply to
1) is anyone using this code -- what was needed to fix it up -- finally?

2) What is the <%ignored%> tag in the search results template? I'm assuming this is something that can be passed in, but what would be the format? (I had originally assumed it was Links telling us what words it ignored, but that doesn't seem to be the case)


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Highlight search terms In reply to
I ended up removing it again as things goes wrong if a user seach for ex: "someting" - the " spoils things..

I have a GT Toolbar instead that supports highlighting :-)


Quote:
2) What is the <%ignored%> tag in the search ..

It is my undertanding that is is not used in the current version of Links - I may be wrong though

Klaus

http://www.ameinfo.com