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

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

I have a, hopefully, quick question.

For a multi-search, there's this piece of code to put on the list page.

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

I was wondering if there were any other options that could be put in this array and what they were, if they're pre-defined anywhere. Ideally, I was hoping to take 'keywords' and maybe use 'query'. Similar to how the difference between a _keyword search and a _query search work using the URL method for a single table list viewer. Right now, the search returns a massive list of results that I'm hoping to narrow down by allowing someone to add keywords to the search field, like using an 'AND' instead of an 'OR'.

I'm also wondering if there's an "ORDER BY" option. It feels like the results are being displayed in a strange order.

Thanks in advance! :)

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

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.

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?

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