Using &highlight in the URL to highlight a phrase

chrisqqgx4

Critical Thinker
Joined
Jul 30, 2003
Messages
291
When specifying a URL, I want to use &highlight to highlight a phrase.

I can highlight a word OK. For instance in this I Love Firefox thread I can highlight the word "Firefox" OK:

http://www.internationalskeptics.com/forums/showthread.php?t=49766&highlight=firefox

but I want to highlight the phrase "I love Firefox". Using

http://www.internationalskeptics.com/forums/showthread.php?t=49766&highlight="I love firefox"

doesn't do it. I've tried the phrase in quotes and using %20 for the space and %22 for quotes around the phrase but that didn't do it either.

Also, I'd like to highlight multiple phrases, I guess with +.

All help gratefully received.
 
Close, but that highlights all occurrences of the words "I" "love" and "firefox" when I want to highlight just that phrase.

This happens on other boards that use the same software (vBulletin I think) so I don't think it's a JREF specific issue. I certainly get the same results when I do something similar on other boards.
 
If it helps this is the code that is called:

PHP:
// *********************************************************************************
// words to highlight from the search engine
if (!empty($vbulletin->GPC['highlight']))
{

	$highlight = preg_replace('#\*+#s', '*', $vbulletin->GPC['highlight']);
	if ($highlight != '*')
	{
		$regexfind = array('\*', '\<', '\>');
		$regexreplace = array('[\w.:@*/?=]*?', '<', '>');
		$highlight = preg_quote(strtolower($highlight), '#');
		$highlight = explode(' ', $highlight);
		$highlight = str_replace($regexfind, $regexreplace, $highlight);
		foreach ($highlight AS $val)
		{
			if ($val = trim($val))
			{
				$replacewords[] = htmlspecialchars_uni($val);
			}
		}
	}
}
 
Thanks Darat, though I didn't understand a word of that!

I searched the vbulletin.org boards, though there was nothing immediately obvious there. Most results were the same code-y stuff that went over my head.
 
OK - delved a bit deeper. I think this is because we use the "old fashioned" vBulletin search method and that means we can't do this kind of search and highlight.

Jelfsoft introduced an option that lets us switch between using the default method (which we use) and letting MySQL handle the indexing of the posts. If MySQL handles the posts I think we can then offer users "boolean" or "natural language" search options and the boolean search option would allow you to do searches such as "love Firefox" - I think. I'll carry on reading and see if boolean search is a possible with the vBulletin indexing.

Let me see what the technical mod thinks about switching to the MySQL indexing.
 
I don't think switching to MySQL indexing will work. Near as I can tell this code is searching for each word to highlight on it's own and isn't using indexing.

I believe the issue arises from this line:
$highlight = explode(' ', $highlight);

there is a space between the ' marks. This line is breaking up the words to be highlighted into an array of words to search for. Most likely the entire URL is URL decoded first (i.e. + and %20's converted to spaces) which is why those hacks didn't quite work as expected.

Also, using " marks as in "this is a phrase" would cause it to highlight the words "this (with the quote at the front) and phrase" (quote at the end) seperately.

Doesn't appear to be a way to force this code segment to highlight a phrase, just words.

I'm not a 100% on this, I know some PHP and some regex but am far from a master at either.
 

Back
Top Bottom