Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Making search results look more, um, "searchy"

Quote Reply
Making search results look more, um, "searchy"
One of the problems I've had on my forums is that many people don't bother to change the subject line when the reply to a message, so when somebody does a search, they could wind up with 25 or 50 seemingly identical results (just with different authors and posting times).

Fortunately, it's pretty easy to modify the search_results template to show something that looks more like what you'd expect from a Google or AltaVista - complete with an excerpt from each hit - with the help of a nice little global somebody posted here for another purpose that looks something like this:

Code:
sub {
my $post_message = shift;

$post_message=~ s/^\s*//; # leading spaces
$post_message=~ s/\s*$//; # trailing spaces
$post_message=~ s/\s+/ /g; # multiple spaces
#
# Strip HTML tags
#
$post_message=~ s(<[^>]*>)()g;
$post_message=~ s(\[url.*\])()g;
$post_message=~ s(\[\/url\])()g;
$post_message=~ s(\[signature\])()g;
$post_message=~ s(\[size*\])()g;
#
return substr($post_message,0,200);
}

What this'll do is give you the first X characters of a post (in my case, I set it to 200 characters) and strip out any HTML and GForum pseudo-HTML (well, the pseudo-HTML that tends to be used in my forums, at any rate).

Now call up your search_results template. Get rid of the table stuff used for include_paging and the results loop and then change the results loop to your tastes (for example, bracket each result with paragraph tags). The key thing is:

Code:
<%if post_message%><%html_strip($post_message)%>...
<br /><%endif%>

(where "html_strip" is the name of your global).

You can see an example of this in action.

Last edited by:

agaffin: Apr 8, 2004, 2:32 PM
Quote Reply
Re: [agaffin] Making search results look more, um, "searchy" In reply to
Smile Great mod - would love it to be implemented on this site!
Quote Reply
Re: [agaffin] Making search results look more, um, "searchy" In reply to
Hello agaffin

Many thank !

hoefti
linktobuy Web Directory
Ratgeber Recht
Quote Reply
Re: [afinlr] Making search results look more, um, "searchy" In reply to
Hi there,

I realize this is an older thread but I'll try to recessitate it. I've got this mod going on my site, but I would like to coordinate it with the search term highlighting plugin.

when I comment out the "strip html" code:

Code:
sub {

use HTML::Entities;

my $post_message = shift;

$post_message=~ s/^\s*//; # leading spaces
$post_message=~ s/\s*$//; # trailing spaces
$post_message=~ s/\s+/ /g; # multiple spaces

#
# Strip HTML tags
#
# $post_message=~ s(<[^>]*>)()g;
# $post_message=~ s(\[url.*\])()g;
# $post_message=~ s(\[\/url\])()g;
# $post_message=~ s(\[signature\])()g;
# $post_message=~ s(\[size*\])()g;
#

return substr($post_message,0,200);

}

I can see the search term highlighting html but the html is encoded so the code renders in the browser, not the html itself. Eg. > is &gt;

I've tried some of the unencoding functions, but nothing works...

Code:
sub {

use HTML::Entities;

my $post_message = shift;

$post_message=~ s/^\s*//; # leading spaces
$post_message=~ s/\s*$//; # trailing spaces
$post_message=~ s/\s+/ /g; # multiple spaces

# Strip HTML tags
#
# $post_message=~ s(<[^>]*>)()g;
# $post_message=~ s(\[url.*\])()g;
# $post_message=~ s(\[\/url\])()g;
# $post_message=~ s(\[signature\])()g;
# $post_message=~ s(\[size*\])()g;

# convert &lt; and &gt; to < and >

#$post_message = GT::CGI::html_unescape($post_message); #

$post_message = decode_entities($post_message);

return substr($post_message,0,200);

}


The html remains encoded so it renders as code.

Can anybody help me here? I'm Going nuts! Pirate


Thanks,
Mike