Wiki source for Mod014fTextSearchImproved


Show raw source

==== Wikka Mod 014 ====
Type: Feature Addition
----
===Credit:===
Heavyk, (k m r @ h e a v y k . o r g)
[[http://www.wakkawiki.com/TextSearchImproved | TextSearchImproved @ WakkaWiki]]
----

====Text search improved====

This update improves the output of the basic textsearch action. The default action with Wakka Wiki is to just return a listing of the WikiWords that matched the search. However, this wasn't nearly enough information to determine what link to click on, especially if there are many search results.

The new output includes a portion of the matching text with the search phrase highlighted.

----

**actions/textsearch.php**
%%(php)
<?php echo $this->FormOpen("", "", "GET") ?>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Search for: </td>
<td><input name="phrase" size="40" value="<?php echo htmlentities($_REQUEST["phrase"]) ?>" /> <input type="submit" value="Search"/></td>
</tr>
</table>
<?php echo $this->FormClose(); ?>

<?php
if ($phrase = $_REQUEST["phrase"])
{
print("<br />");
if ($results = $this->FullTextSearch($phrase))
{
print("<strong>Search results for \"$phrase\":</strong><br /><br />\n");
print "<table border=0 celpadding=0 cellspacing=0>";
$STORE_FORMATING_AS_TEXT = 1;
foreach ($results as $i => $page)
{
//print(($i+1).". ".$this->Link($page["tag"])."<br />\n");
//print implode($this->LoadPage($page["tag"]));
//$matchString = preg_match("/(.{0,40}$phrase.{0,40})/",implode($this->LoadPage($page['tag'])));
/* display portion of the matching body and highlight
the search term */
preg_match("/(.{0,120}$phrase.{0,120})/is",$page['body'],$matchString);
$text = $matchString[0];
include("formatters/wakka.php");
$highlightMatch = preg_replace("/($phrase)/i","<font color=green><b>$1</b></font>",$text,-1);
$matchText = "<font color=gray size=-1>...</font>$highlightMatch<font color=gray size=-1>...</font>";

print "

<tr>
<td valign=top align=right>
<!-- result number -->
<table>
<tr>
<td valign=top align=left bgcolor=#DDDDDD>
<font color=white size=-3>
".($i+1)."
</font>
</td>
</tr>
</table>
</td>
<!-- link -->
<td valign=top>
".$this->Link($page["tag"])."
</td>
<!-- date of last update -->
<td valign=top align=right>
<font color=gray size=-3>
$page[time]
</font>
</td>
</tr>
<tr>
<td>
 
</td>
<td colspan=2>
$matchText
</td>
</tr>
<tr>
<td>
 
</td>
</tr>

";
}
print "</table>";
}
else
{
print("No results for \"$phrase\".");
}
}
?>
%%

In order to properly format the matching text the following small modification must be made to the **formatters/wakka.php** file. Modify the last line of the file. It should originally read

print($text);

The new version should read

if (!$STORE_FORMATING_AS_TEXT) print($text);

----

Heavyk, 3/8/04 (k m r @ h e a v y k . o r g)
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki