Index: searchlib.php
===================================================================
RCS file: /cvsroot/tikiwiki/tiki/lib/search/searchlib.php,v
retrieving revision 1.19.2.19
diff --unified=3 -r1.19.2.19 searchlib.php
--- searchlib.php	12 May 2006 18:07:15 -0000	1.19.2.19
+++ searchlib.php	19 Jul 2007 13:22:57 -0000
@@ -764,10 +764,23 @@
 	   if($this->user_has_perm_on_object($user,$res["page"],'wiki page','tiki_p_view')) {
             $href = "tiki-index.php?page=".urlencode($res["page"]);
             ++$cant;
+            $chunksize = 250; $offs = -1; $startoff = 0;			// start: clean the output to remove wiki markup
+			$data = html_entity_decode(strip_tags($this->parse_data($res["data"])));
+																	// parse the wiki source, strip_tags and entity decode
+																	// a bit heavy handed - would prefer to leave simple text formatting tags in
+			$offs = strpos($data, stristr( $data, $words[0] ));		// just the first one's pos - workaround for no stripos() in php4
+			$startoff = $offs - ($chunksize / 2);					// start of result chunk
+			if ($startoff < 0) { $startoff = 0; }					// correct for chopped off words at front...
+			while($startoff > 0 && preg_match("/\S/", $data[$startoff])) {
+				--$startoff;
+			}														// and tidy the end
+			while($chunksize > 200 && preg_match("/[\S\w]/", $data[$chunksize + $startoff])) {
+				--$chunksize;
+			}
             $ret[] = array(
               'pageName' => $res["page"],
               'location' => tra("Wiki"),
-              'data' => substr($res["data"],0,250),
+              'data' => substr($data, $startoff, $chunksize),		// end: clean the output to remove wiki markup
               'hits' => $res["hits"],
               'lastModif' => $res["lastModif"],
               'href' => $href,
