Options Available for $searchOptions Array in Multi-Search

6 posts by 3 authors in: Forums > CMS Builder
Last Post: March 15, 2013   (RSS)

By JLynne77 - February 7, 2013 - edited: February 7, 2013

Just hoping to get a response. I have a client asking about it for their site, because the results are showing up in a strange place.

If it helps:

http://test.suffolkfcu.org/

If you type in a search for 'savings' with no quotes, the personal savings account page (which is the one most likely to be looked for) doesn't come up until page two. If I add personal or account or even both, it doesn't seem to help narrow the results to that page. Most of the searches seem to be working this way.

-----
~Jessica Sullivan, Crystal Realm Designs.

By gregThomas - February 8, 2013

Hi Jessica,

Sorry for the delay in reply.

The searchMultipleTables function is currently an experimental feature with limited functionality, the only filter option it currently has is for keywords.

The searchMultipleTables function collects results in the order the table items are added to the array. For example:

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

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


Would collect news results, then blog results. If you reordered them like this:

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

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

Then blog results would be collected first. So I would put sections that people are most likely to want results from at the top of the list, and least likely at the bottom.

There are currently only 4 searchOptions you can use in the searchMultipleTables function, the final one being the orderBy option. You can use this to as you would the orderBy function in a getRecords function. For example:

//NOTE: Because of a bug you always need to have a space at the end of the string.
$searchOptions['orderBy'] = "_title DESC ";

Would return results from each section ordered by there title. 

There is a bug in the orderBy functionality that means you will need to add a space at the end of the string.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By JLynne77 - February 11, 2013

Thanks, Greg. This helps a lot. :)

-----
~Jessica Sullivan, Crystal Realm Designs.

By mdegive - March 15, 2013

I also only would like an additional where clause "where publish=1", is this possible?

By gregThomas - March 15, 2013

Hi,

This behavior isn't available by default, but you can make a quick modification to the CMS Builder code to add it. If you open cmsAdmin/lib/viewerFunctions.php and add this code around line 1179:

    $where            = _addWhereConditionsForSpecialFields($schema, '', $searchOptions);

    if(@$tableOptions['customWhere']){
      if($where){
        $where .= "AND ".$tableOptions['customWhere'];
      }else{
        $where = 'WHERE '.$tableOptions['customWhere'];
      }
    }

    $subquery         = "SELECT '$tablename' as `tablename`, num, `{$tableOptions['titleField']}` as `_title`, ";

Now you have the option to add custom where statements for each table search, here is an example of how you might use it:

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

$searchTables = array(); 

$searchTables['blog'] = array( 
'viewerUrl'    => 'index.php', 
'titleField'   => 'title', 
'summaryField' => 'title', 
'searchFields' => array('title'), 
'customWhere'  => "published = '1'"
); 


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


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

So when a search is carried out on the blog table, only records with the published checkbox selected will be returned.

Note: This change requires the modification of core CMSB files, if you upgrade at a later date these changes will be lost.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com