multiSearch - How to Exclude Records from Search

5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 31, 2015   (RSS)

By Perchpole - March 30, 2015

Hi All -

Is there a way to exclude selected records from a multiSearch? There are often certain pages on my sites which shouldn't be viewed unless the user first comes from another page. The search gives them direct access in a way that should be possible by normal means.

I understand there isn't a "where" function in multiSearch - so I wondered if there was any other way I can make it skip records flagged with a particular value?

Perch

By Damon - March 30, 2015

Hi,

One way you can exclude records from the multiSearch would be to use the "hidden" checkbox on the record. The record would then not appear in the search results.

To be able to link to the record directly and it have it display (even when marked as hidden) would  require that you add the following to the View Options:

'ignoreHidden'      => true,  // don't hide records with hidden flag set

Hope this helps. If you need any additional details about the steps or have questions, just let me know.

Thanks!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Perchpole - March 30, 2015

Hi, Damon -

Thanks for your input. Unfortunately the "hidden" option is already factored into this set-up. There are some records which are hidden on the site - which multiSearch will not find. Then there are some records which are visible but which I want to exclude from multiSearch.

For example this could include a "Thank you" page after a user has filled in a form. It's not hidden - I just don't want the search to find it!

:0)

Perch

By Damon - March 31, 2015

The best method is to use hidden checkbox and ignoreHidden option to show hidden records on the site but not in the search results. This works well because the search results number of records found and the prev and next links based on a set number of results will work correctly.

But, if this isn't going to work with your setup, then another option is to create a new checkbox to Hide from multSearch.  Here are the steps to setup:

In your multi-search page, edit to add the blue code:

$searchTables['new'] = array(
'viewerUrl' => '/news_detail.php',
'titleField' => 'title',
'summaryField' => 'content',
'field1' => 'hide_from_multsearch',
'searchFields' => array('title','content'),
);

Next further down in the code right after the foreach loop to display the results add this blue code:

<!-- STEP2: Display Record List -->
<?php foreach ($searchRows as $record): ?>
<?php //showme($record); ?>
<?php if($record['field1'] == 1) { continue; } ?>


This will skip records with field1 (hide_from_multsearch) is checked (1).

The problem with this method is you will need to either remove the number of search results and pagination results or recreate them with code. So for example to get the number of search results, you could setup a counter and then output the results.

Let me know what you think.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/