I found a mod I did to the action.dosearch.php. See below for instruction:
1) Add this function to the beginning of the file:
Code: Select all
// MOD START (Part 1 of 2)
// SCRIPT BY lixlpixel PHParadise - http://www.fundisom.com/phparadise/
function ReturnPos($AStringMaster,$AStringSlave)
{
$CP=0;
while (strlen($AStringMaster)>=$CP)
{
unset($asubstring);
$AStringSlave=strtolower($AStringSlave);
$AStringMaster=strtolower($AStringMaster);
$ASubString=substr($AStringMaster,$CP,strlen($AStringSlave));
if ($ASubString==$AStringSlave) return $CP;
$CP++;
}
return -1;
}
// MOD END - by nhaack
It is used for finding the first occurence of the search term in the content snippet (only block "content_en"), so we can highlight it.
Then add the second modification :
Code: Select all
// MOD START (Part 2 of 2)
//RETURN POSITION OF STRING IN STRING
//Get content block "content_en" associated with the single search result item and store it in the variable $bufferme
$bufferme = strip_tags($content->GetPropertyValue('content_en'));
//Store startposition of not-case-sensitive searchword match (if any) by using function added above
$CutPosition = ReturnPos($bufferme,$params['searchinput']);
//Put a bold hmtl tag (<strong>) around the matching first word
if ($CutPosition > -1)
{
//Insert beginning <strong> tag right before the word
$bufferme = substr_replace($bufferme,'<strong>',$CutPosition,0);
//Insert ending </strong> tag right after the word (=start position + length of <strong> (becasue string is longer now) + length of searchword)
$bufferme = substr_replace($bufferme,'</strong>',$CutPosition+8+strlen($params['searchinput']),0);
}
//If found word that has been bolded starts with the first 50 characters (or is not existent): show first 160 characters of text
// else trim beginning char up to 47 chars before actually found word. Assign text to variable $searchsummary
If ($CutPosition >49)
{
$searchsummary = '...'.substr($bufferme,$CutPosition-47,160).'...';
}
else
{
$searchsummary = substr($bufferme,0,160).'...';
}
// Modified: inserting $searchsummary insteadt of title to the Search results
$col->AddItem($searchsummary, $content->GetURL(), $content->Name(), $result->fields['total_weight']);
// MOD END - by nhaack
Insert the second snippet around line 80 (something) where code looks like this:
Code: Select all
.......
$content =& $node->GetContent();
if (isset($content))
{
SECOND PART OF MOD GOES HERE
}
}
}
else if ($result->fields['extra_attr'] == 'template')
{
.......
You now have an abstract that you can acces like this in your search result template:
Code: Select all
.......
<h3><a href="{$entry->url}">Title: {$entry->urltxt}</a> [{$entry->weight}%]</h3>
<p>Abstract: {$entry->title}</p>
<span class="sr_url">{$entry->url}</span>
..............
I haven't used that mod recently, so I do not know if it is compatible with the current version.
Please keep in mind, you are modifying core files. This happens at your own risk. I doubt it is a very elegant version, but it played nicely on a site of mine.
Hopefully this can give you a hint on how to achieve it. The comments in the code should get you going (so you could simplify it a bit).
Best
Nils