SimpleSearch: Can we exclude containers in search results?

With SimpleSearch, is there an easy way to exclude containers or the resources where [[*isfolder]] = 1 from the search results?

I’m currently using the exclude document ID, but it is at 54 numbers and keeps growing every month. I’m hoping there is a more compact and efficient way to automatically ignore all the containers.

Or perhaps whoever wrote the snippet can take this as a feature suggestion to update the snippet?

As far as I can see, there is no built-in way to exclude folders.
However, the code checks if the flag searchable is set to true. So maybe you can just set searchable for all your folders to false.

If you manage the exlude id list by hand, then you can automate it by calling a snippet to generate the list.

[[!SimpleSearch? &exclude=`[[getFolders]]` &ids=`1`]]

Snippet getFolders:

$resources = $modx->getIterator('modResource', array('isfolder' => '1'));
$out = array();
foreach ($resources as $resource) {
    $out[] = $resource->get('id');
return implode(",",$out);
1 Like

Unchecking “searchable” works fine, and illuminated something I didn’t realize which is that you can actually have folders with the container field unchecked. So filtering by that field would not have automatically worked perfectly anyway.

1 Like

I think the current rule (the last time I checked) is that whenever you save a resource (new or old) that has a parent, the parent’s container field will be set automatically.

The reverse happens when you delete the only remaining child of a parent.

So the bottom line is that you can have a folder that doesn’t have container field set, but it may not stay that way.

I believe the first edition of my book has the wrong information on this topic, though AFAIK, it was correct when I wrote it.