HelpSpot Help Desk Software | HelpSpot Blog | HelpSpot Support

Customize Search Results


#1

I would like to customize the search results. We’ve currently got three areas: Knowledge Books, Online Training and Training Videos. Currently, the results from all three area’s are intermixed in the results. I’d like to have the results grouped by area, and then sorted by relevance.

The current code in search.tpl.php looks like this:

<?php foreach($this->splugin('Search','search', $this->get_q, $this->get_area) AS $result): ?>
<td>
	<a href="index.php<?php echo $result['link'] ?>"><?php echo $result['title'] ?></a> <br /> <?php echo $result['desc'] ?>
</td>
<td class="score">
	<?php echo $result['score'] ?>
</td
<?php endforeach; ?>

I know very little about PHP, although I am proficient in a number of other languages, so if I’m off base in some of my assumptions please feel free to correct me.

The call to splugin(‘Search’,… I believe is calling Search.php, which has been encoded or otherwise obfuscated. Is this call documented anywhere? What exactly is returned in the $result[] object? If the area is returned then I could probably figure out the PHP to do what I want (i.e. just process each area seperately).

Note that the <td class=“score” closing element is missing the end tag (>) - probably an issue with the provided templates.


#2

Ah, found a php function var_dump… I may have this solved…


#3

Hi Tyler,

Yes, var_dump or print_r() are useful for looking into the array returned. Let me know if you have any questions after poking around with that a bit.


#4

got it figured out, had to learn a little php, but it’s very similar to a couple of other languages so wasn’t too tough - here’s the end result - appreciate any feedback on my noob PHP script…

<?php $td = array(); // Tech Docs $tv = array(); // Training Video $ot = array(); // online training $kb = array(); // other Knowledge Book foreach($this->splugin('Search','search', $this->get_q, $this->get_area) AS $result) { switch($result['sBookName']) { case "TechDocs": array_push($td, $result); break; case "Free Online Training": array_push($ot, $result); break; case "Training Videos": array_push($tv, $result); break; default: array_push($kb, $result); } }?> <?php if(count($td)>0): ?>

TechDocs (<?php echo count($td) ?>)

<?php endif; ?> <?php foreach($td as $result): ?>
... original code here ...
<?php if(count($tv)>0): ?>

etc etc.


#5

That seems fine Tyler, nice job.