6 posts by 2 authors in: Forums > CMS Builder
Last Post: July 25, 2013   (RSS)

By weblm - July 24, 2013 - edited: July 24, 2013

In response to: [url "http://www.interactivetools.com/forum/forum-posts.php?postNum=2229396#post2229396"]Options Available for $searchOptions Array in Multi-Search[/url], ...

Greg,

I was wondering....is there ANY options available to take the results of a multisearch, and sort the resulting array by the createdDate field?  I really don't want the results being grouped by the table if possible.  

I'm able in my multisearch to add the folllowing to each $searchTables routine:

'field1'   => 'createdDate',

This gives me access to the date field.

I can then run that through a sort function to sort the array:

function date_sort2($a, $b) {
    $t1 = strtotime($a['field1']);
    $t2 = strtotime($b['field1']);
    return $t2 - $t1;


usort($searchRows, 'date_sort2');

This works great except it breaks with pagination.  I'm guessing the way pagination works is that is only displays the records based on perPage.....so each page it re-runs the query and redoes the sort.  Not want I want.

Any ideas?

I'm guessing at this point my only option might be to display ALL the search results at once, and use some jQuery pagination code to do faux pages?

-Kevin

By weblm - July 24, 2013 - edited: July 24, 2013

Ok, well to test I did accomplish this using jQuery and a pagination plugin.  It works.  Basically I put the per page option to 1000.....and have the plugin to the pagination.

I think if I go this way, I'll also array_slice the sorted array to artificially keep the overall size down to something manageable.

Does this sound like the best way to solve this?

-Kevin

BTW: The jQuery pagination code I'm using is from here: http://dl.dropboxusercontent.com/u/4151695/html/pajinate/examples/example1.html

Very simple to implement.

By weblm - July 25, 2013

Holy cow......that is way too easy.  Guess I should have waited for a response ;-)

Can I ask.....can this multi search functionality be used to grab all the articles from multiple tables, and just return them in date order?

Here's what I mean......I have multiple sections in the CMS that on the site are all grouped under the umbrella of Resources.  So each of these sections has it's own list page.  What I'd like to do is create a master Resources page that grabs ALL the records from all the sections, sorts them by createdDate, and lists them on a master resources page.  I know I can do this with multiple getRecords calls and then array_merge and sort, like what I was going to do on the search page.....but again my problem is pagination.  I can't use the CMS Builder pagination code on a merged array.

Can this multi-search functionally be used to just return ALL records sorted by createdDate?  Or can you think of another way?

-Kevin

By gregThomas - July 25, 2013

Hi Kevin, 

I've just done a quick bit of testing, and this is possible, here is some example code:

// site search stuff
$searchOptions = array();
$searchOptions['keywords'] = ':';
$searchOptions['perPage']  = "20";
$searchOptions['debugSql'] = "1";
$searchOptions['orderBy']  = 'field1 DESC ';


$searchTables = array();

$searchTables['blog'] = array(
'viewerUrl'    => 'test.php',
'titleField'   => 'title',
'summaryField' => 'content',
'searchFields' => array('createdDate'),
'field1'       => 'createdDate',
'field2'  => 'subject'
);

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

So I've changed it so that the keyword that is searched for is always ':', and then changed the searchTables arrays so that they always search the createdDate field. As a createdDate field will always have a colon in, all the contents of the tables will always be returned. The tables will also be ordered by the createdDate.

Cheers

Greg

Greg Thomas

PHP Programmer - interactivetools.com

By weblm - July 25, 2013

Greg,

Let me know where I can send a Christmas gift this year!!!!  This is awesome.  It looks like it's working great.   I have a few more things to sort out and test and will let you know if I run into any issues....but so far this is doing exactly what I need it to.

Thank you so much.

-Kevin