Multisearch Results Order

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 16, 2011   (RSS)

By zip222 - June 15, 2011

Is there way to change the order of the returned results when using multisearch? Right now they come back grouped by each table using the default order for that table. I am looking for all results to come back blended together, and ordered by updatedDate.
Is this possible?

Re: [zip222] Multisearch Results Order

By Jason - June 16, 2011

Hi Zip,

Yes. What you can do is return up to 10 other fields by adding them to the table options arrays. For example, to return the updatedDate would be like this:

$searchTables['news'] = array(
'viewerUrl' => 'newsPage.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title'),
'field1' => 'updatedDate',

);


You would do this for each of your sections.

Next, put this function down at the bottom of your page:

<?php
function subval_sort($a,$subkey, $direction = "ASC") {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
}
if ($direction == "DESC") {
arsort($b);
}
else {
asort($b);

}
foreach($b as $key=>$val) {
$c[] = $a[$key];
}
return $c;
}
?>


You can then sort your turned results by field1 like this:

$serachRows = subval_sort($searchRows,'field1','DESC');

You can replace DESC with ASC to switch from descending to ascending order.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/