1 philip Oct 09, 2003 17:16
3 basstech Oct 09, 2003 23:25
I made a hack for b2 to do it.
And I've applied the hack in b2evo...
I can post it here if you want.
It uses php and not javascript.
If you wanna read more the hack in b2 go here: http://tidakada.com/board/viewtopic.php?p=20347#20347
You can see it on my b2evo here: http://evo.team-geek.net (please note my b2evo blog is under heavy construction.)
4 philip Oct 13, 2003 23:38
yes please!
I used to use yours with b2 :D
5 basstech Oct 13, 2003 23:46
Ok...
Sorry this is a little late, but here's how to do it in b2evo.
Open up blogs/b2evocore/_functions_bposts
Near the top below
if( $use_textile ) require_once (dirname(__FILE__).'/_functions_textile.php');
Add
require_once (dirname(__FILE__).'/searchhighlight.php');
Around line 535 look for ' echo $content; ' just before it but after the last '}' add this code:
//search highlight hack
if (isset($s)&&$s!="") {
$searchwords = explode(" ", $s);
$class = 1;
for($i = 0; $i <= count($searchwords); $i++) {
$content = getHTMLHighlight($searchwords[$i], $content, "<span class=\"searchword".$class."\">", "</span>");
if ($class == 1) {
$class = 2;
} else {
$class = 1;
}
}
}
Now create a file in blogs/b2evocore/ called searchhighlight.php
Copy and Paste the following code into it.
<?php
function getHTMLHighlight($needle, $haystack, $hlS, $hlE)
{
$parts = explode(">", $haystack);
foreach($parts as $key=>$part)
{
$pL = "";
$pR = "";
if(($pos = strpos($part, "<")) === false)
$pL = $part;
elseif($pos > 0)
{
$pL = substr($part, 0, $pos);
$pR = substr($part, $pos, strlen($part));
}
if($pL != "")
$parts[$key] = preg_replace('|\b('.quotemeta($needle).')\b|iU', $hlS.'\\1'.$hlE, $pL) . $pR;
}
return(implode(">", $parts));
}
?>
This code highlights searchwords two different colors defined in your css.
the classes for the css are: searchword1 and searchword2.
It will alternate between colors, so if you search for 3 words the first will be color 1, the second color 2, and the third word will be color 1.
If you want all the words the same color, just set searchword1 and searchword2 to be the same.
Here: is the css I use on www.team-geek.net
.searchword1 {
background-color: #F90;
color: #06C;
}
.searchword2 {
background-color: #06C;
color: #F90;
}
6 philip Oct 14, 2003 11:26
this oughta be incorporated in b2evo! :D
But, I can not make it work. I've done everything you said, but still http://republicum.se shows nothing when I search for a word :(
Don't mind it being in swedish ;)
7 basstech Oct 14, 2003 15:59
I took a look. It's not working. Could you do me a favor. Could you make a copy of _functions_bposts.php and name it _functions_bposts.phps.
I'll look at it to make sure you added the code in the right place. That's the only thing I can think of that is wrong.
8 basstech Oct 14, 2003 16:02
Here are some samples of it working on my two blogs:
http://www.team-geek.net/basstech.php?s=kitten&sentence=AND&submit=Search
http://www.team-geek.net/index?s=ant+weight
9 philip Oct 14, 2003 17:27
copy made :)
10 basstech Oct 14, 2003 18:29
Ok....
It was my fault. I left out an essential piece of code.
You need to go upto to top of the the_content() function.
Just below the function declaration (should be line 515) replace:
global $use_textile;
global $use_textile, $s;
This is essential for the function to see the searchwords because they are contained in $s.
It should work after that, as you placed the rest of the code in the right places.
11 philip Oct 14, 2003 21:14
it gets all fucked up :/
and the åäö gets decoded too. hmm :(
12 basstech Oct 14, 2003 21:36
I haven't used it with any other languages.
I'm going to take a look at your site and see what it's doing.
13 basstech Oct 14, 2003 21:59
Ok....
I'm gonna have to look into this.
For some reason it's getting false positives on nothing. I never noticed it because my css only highlights. It doens't do any boxes or borders. For the time being, if you removed the margins, padding, and border from you searchwards classes, it will look alot better. Hopefully I'll have an answer by this evening.
14 philip Oct 14, 2003 22:28
it wont search backwards either.
hmm, maybe i'll just remove the code until it's incorporated into b2evo.
Can't figure shit out. the php looks okay though.
great job!
15 basstech Oct 14, 2003 23:02
Grrr...
I figured out the problem.
for($i = 0; $i <= count($searchwords); $i++) {
Should be:
for($i = 0; $i < count($searchwords); $i++) {
I don't know about the character encoding.
I'm american, and have never done any coding with other languages then english.
Let me know how it turns out.
I'll be glad to help.
16 basstech Oct 14, 2003 23:12
I figured I'd share this too. I have this code at the top of my _main.php right before the posts start.
<?
if (isset($s)&&$s!="") {
?><h4>Search results for: </h4><?
$searchwords = explode(" ", $s);
$numwords = count($searchwords);
foreach($searchwords as $key => $searchword) {
echo "\"".$searchword."\" ";
if ($key != ($numwords -1)) {
echo " & ";
}
}
}
?>
Demo: http://www.team-geek.net/basstech.php?s=the+kitten+blog+b2evo&sentence=OR&submit=Search
17 philip Oct 14, 2003 23:59
it's working now! thanks.
Now to understand why my categories are bugging and why the search wont search older posts :(
18 basstech Oct 15, 2003 03:20
I don't know anything about it not searching older posts. Both my blogs are pretty new. I haven't experienced that with mine.
19 philip Oct 16, 2003 19:10
http://republicum.se/index.phps
i know you're better at php than me. can you please check to see if there's anything wrong here? :/
20 basstech Oct 18, 2003 17:19
Sure no problem. At first glance I don't see anything wrong. I'll get back to you on it in a bit
21 philip Oct 19, 2003 00:19
thanks a million. hmm
lemme update that phps :)
it'll be done 2 secs after this post :P
the search acts funny.
just try to copypaste words from older posts and search them from the front page.
also, when me and my girlfriend search simultaneously we got different results on the same search.
it's really weird
22 basstech Oct 19, 2003 06:16
I didn't experince any problems finding older posts.
It looks like you turned the highlight off though.
I'm sure if it might be a text encoding thing. Your one post per page layout makes searches kind of restrictive, and I think the problem might be that. If you search for something that is in both an older and a newer post, you only going to see the newest post, Also finding no posts breaks your layout just a little bit. You might want to use css to force the height of your layout div's to be 100% or something.
23 philip Oct 19, 2003 23:10
i have 2days of posts shown on my site, and yeah i turned highlight off because sometimes it highlighted and sometimes it didn't.
height:100% on a div-layer breaks weirdly in firebird and ie, so i have 500px padding-bottom instead.
as you can see nav_link doesn't show either.
something is wrong :/
thanks so far :D
24 nomad Jul 22, 2005 21:58
Any news on this? As the hack is two years old... will it work in the newest version? Thanks
It's not there at the moment, but since I'm not writing the software (just testing it), I've no idea when Francois is planning on implementing it (if he is at all).