MultiSearch - orderBY date DESC

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

By Zicky - June 21, 2016

Anyone know how to order the MultiSearch results by date DESC

//SEARCH CODE

$searchOptions = array(); 
$searchOptions['keywords'] = @$FORM['q']; 
$searchOptions['perPage'] = "15"; 
$searchOptions['debugSql'] = "0"; 

$searchTables = array(); 

$searchTables['thome'] = array( 
'viewerUrl' => 'index.php', 
'titleField' => 'title', 
'summaryField' => 'text', 
'searchFields' => array('text'), 
); 

$searchTables['history'] = array( 
'viewerUrl' => 'history.php', 
'titleField' => 'title', 
'summaryField' => 'text', 
'searchFields' => array('title','text'), 
); 

$searchTables['news'] = array( 
'viewerUrl' => 'news.php', 
'titleField' => 'title', 
'summaryField' => 'text', 
'searchFields' => array('title','text'), 
); 

list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);

$searchRow = @$searchRows[0];

Thanks Zick

By gregThomas - June 21, 2016

Hey Zick, 

Something like this should work:

//SEARCH CODE
$searchOptions = array(); 
$searchOptions['keywords'] = @$FORM['q']; 
$searchOptions['perPage'] = "15"; 
$searchOptions['debugSql'] = "0"; 
$searchOptions['orderBy']  = "`field1` DESC";


$searchTables = array(); 

$searchTables['thome'] = array( 
  'viewerUrl'    => 'index.php', 
  'titleField'   => 'title', 
  'summaryField' => 'text', 
  'searchFields' => array('text'), 
  'field1'       => 'createdDate',
); 

$searchTables['history'] = array( 
  'viewerUrl'    => 'history.php', 
  'titleField'   => 'title', 
  'summaryField' => 'text', 
  'searchFields' => array('title','text'), 
  'field1'       => 'createdDate',
); 

$searchTables['news'] = array( 
  'viewerUrl'    => 'news.php', 
  'titleField'   => 'title', 
  'summaryField' => 'text', 
  'searchFields' => array('title','text'), 
  'field1'       => 'createdDate',
); 

list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);

$searchRow = @$searchRows[0];

The multi search system allows you to set the contents of a field from a particular section to variables with names field1 - field10.

So for each section that get's searched I'm setting the createdDate of the records to the custom field field1. Then I've added an orderBy statement to the options that will sort by field1. You can use a different date field for each section if required.

Let me know if you have any questions. 

Cheers,

Greg

Greg Thomas

PHP Programmer - interactivetools.com