MultiSearch

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

By Toledoh - July 16, 2013 - edited: July 16, 2013

Hi All,

In multisearch.php, you have the "'titleField'      => '????'," to act as the title of the found record.  Is there a way that I can join 2 fields here?

ie: 'titleField'      => 'surname','first_name',

Thanks!

Cheers,

Tim (toledoh.com.au)

By Toledoh - July 18, 2013

Perfect Greg!

Any way that I can add separators like a comma or space?

It would be great to be able to have first_name surname - position (ie. separate with a space and a "-" as required)

Cheers,

Tim (toledoh.com.au)

By gregThomas - July 19, 2013

Hi Tim,

I've found a way that you can add strings into the concat statement, you need to update line 1178 from this:

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

to this:

    if(is_array($tableOptions['titleField'])){
      $fieldArray = array();
      foreach($tableOptions['titleField'] as $option){
        $fieldArray[] = (substr($option, -2) == ':s')? "'".substr($option, 0, -2)."'": "`$option`";
      }
      $fieldString = implode(",", $fieldArray);
      $subquery         = "SELECT '$tablename' as `tablename`, num, CONCAT($fieldString) as `_title`, ";
    }else{
      $subquery         = "SELECT '$tablename' as `tablename`, num, `{$tableOptions['titleField']}` as `_title`, ";
    }

The line I've modified is highlighted in green. So now an if statement checks to see if :s is applied to the end of a string, if it is it treats it as a string for the concat list as opposed to a table name, so if I wanted to add '  - ' in-between my title and subject fields, my searchTables array would look like this:

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

Let me know if you have any questions.

Cheers

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Toledoh - July 23, 2013

Hey Greg - that works perfectly!

Can I suggest that this be included in future releases?

Cheers,

Tim (toledoh.com.au)

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

Hi Tim,

At some point soon we'd like to rewrite the multi search functionality completely (it's still technically an experimental feature), so we'll leave this functionality out for now.

I've also just found a much easier method for getting multiple fields and displaying their content:

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

So you can use field1 to field10 to retrieve as many additional fields for a section as you require, then you can display the extra content like this:

<a class="search-result-title" href="<?php echo $record['_link'] ?>"><?php echo $title_prefix ?> &raquo; <strong><?php echo $record['_title'] ?> - <?php echo $record['field2']; ?></strong></a>

This functionality is already built into CMS Builder, so there is not need to make changes to the core code either.

Cheers

Greg

Greg Thomas







PHP Programmer - interactivetools.com