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
Subject Author Views Date
Thread Making search results look more, um, "searchy" agaffin 2886 Apr 8, 2004, 2:30 PM
Thread Re: [agaffin] Making search results look more, um, "searchy"
afinlr 2822 Apr 8, 2004, 2:48 PM
Post Re: [afinlr] Making search results look more, um, "searchy"
Swaylock 2611 Feb 12, 2006, 11:25 PM
Post Re: [agaffin] Making search results look more, um, "searchy"
hoefti 2813 Apr 9, 2004, 2:45 AM