WP Search page results – how to display Match percentage

I haven’t seen it so far implemented in WordPress, anybody else? OK, here’s a little piece of code which will allow you to set the Match percentage on search result page of your WordPress theme. I guess it’s not hard to represent it graphically if one prefers, however I’ll stay focused on information only.
Yeah I know, many will say this info is not relevant or accurate enough but I found it quite useful when searching for specific phrase or string in the woods of search results.


<?php
	// 'search.php'...get the search string $_GET[ 's' ], compare with content
	similar_text( $_GET[ 's' ], get_the_content(), $percentMatch );
    // round up result
	$percentMatch = round( $percentMatch * 100 );
    // get rid of inflates
	if( $percentMatch > 100 ) $percentMatch = 100;
    // output result
	echo 'Match: <strong>' . $percentMatch . '%</strong>';
?>

Note that you will have to use this code within the loop. Otherwise get_the_content() is quite useless. I’m not sure whether similar_text() may affect server’s performance and slow down your site a bit…I guess there are people knowing better than myself and willing to share their knowledge.

Share with others...

deliciousdiggreddittechnoratifacebooktwittergoogleyahoowikioblinklistsimpyspurl
Comments (1)

Track comments via RSS 2.0 feed. Feel free to post the comment, or trackback from your web site.

  • Mikey on Jun 18, 2009

    That’s just cool idea, I’ll definitely make it alive in my next project, thanks for sharing it Feeleep!

Leave a Comment

Search

Latest Twitts

  •  

Advertisement

GraphicRiver ThemeForest