Page 1 of 1

Search Results - displaying content

Posted: Wed Feb 04, 2009 10:07 am
by lainyrache
Hi

Does anyone know if it is possible to display a few lines of content in Search Results?
The only extra mod I'm using is News.
I would like my search results to display the title, and then the first few lines of content or summary.

Thanks for any help  :D
Rachael

Re: Search Results - displaying content

Posted: Wed Feb 04, 2009 11:14 am
by viebig
I did a mod like that, not so easy. To be honest I lost updated files...

I´ll let you know if I can do it again or find it somewhere.

Regards,

G

Re: Search Results - displaying content

Posted: Wed Feb 04, 2009 11:26 am
by jorgwata
Hi everybody,

Viebig, do you know if there is an easy way to implement third-party search scritps in an existing CMSMS implementation?

Portuguese translation: Grande Viebig, tenho acompanhado suas intervencoes no forum e fico orgulhoso de termos um compatriota tao participante e tao conhecedor do sistema. Voce sabe se é facil implementar um script de busca de terceiros (tipo Google) no CMSMS? Pergunto isso porque a pagina de resultados do modulo Search é muito pouco flexivel

Regards,

Re: Search Results - displaying content

Posted: Wed Feb 04, 2009 12:46 pm
by lainyrache
thanks viebig

Thought it might be a bit tricky, am also a bit concerned that it will make the search slow...?

On another search issue - I know this should probably be another topic... I just wondered if you know of a quick and easy way to encode ampersands in the form action on the search results page. This is causing a problem with validating the html.
I'm sure I've seen the answer to this on the forum somewhere, but now I'm looking for it I can't find it!

eg my form tag on a search results page looks like this:

Code: Select all

<form id="cntnt01moduleform_1" method="get" action="http://www.lalala.org.uk/cms1/cms2/?mact=Search%2Ccntnt01%2Cdosearch%2C0&cntnt01returnid=109&cntnt01searchinput=lorem&submit=Go&cntnt01origreturnid=15">
thanks again
Rachael

Re: Search Results - displaying content

Posted: Wed Feb 04, 2009 8:49 pm
by nhaack
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

Re: Search Results - displaying content

Posted: Fri Feb 06, 2009 5:15 pm
by lainyrache
Hi nhaak
thanks so much for posting such a detailed response!
That is incredibly helpful.
I will give this a go. I'm also trying out pisearch module, which I think does pretty much what your mod does as default.

:)
Rachael