Hi Keakie
Thanks for this very interesting hint!
I have found already a solution where I run cms:pages with the option ids_only='1' several times and then consolidate these lists together with cms:php.
Using this approach I was able to create a multi-substing-search: When somebody types in e.g. "omas uster" it finds a record with firstname="Thomas" and lastname="Muster".
Here is my solution, if someone can make use of it. Probably I will use the SQL-Variant later, this might give better performance:
- Code: Select all
<!-- Getting the search srting sent via POST-->
<cms:set search_string="<cms:gpc 'search' method='post' />" />
<!-- Creating substrings where a blank is -->
<cms:set search_strings="<cms:php>echo trim(implode('|', explode(' ', '<cms:show search_string />')),'|');</cms:php>" />
<cms:set found_ids="" scope='global' />
<!-- Cycling through all substrings -->
<cms:each search_strings>
<cms:set tmp_ids="" scope='global' />
<!-- Search in multiple editables with OR: For each substring look at the relevant editables and getting ids for all found cloned pages, create a list of all ids, even if ids are listed multiple times -->
<cms:set tmp_ids="<cms:show tmp_ids />,<cms:pages masterpage='anfragen.php' custom_field="gewerk=<cms:show item />" ids_only='1' />" scope='global' />
<cms:set tmp_ids="<cms:show tmp_ids />,<cms:pages masterpage='anfragen.php' custom_field="status=<cms:show item />" ids_only='1' />" scope='global' />
<cms:set tmp_ids="<cms:show tmp_ids />,<cms:pages masterpage='anfragen.php' custom_field="datum_anfrage=<cms:show item />" ids_only='1' />" scope='global' />
<cms:set tmp_ids="<cms:show tmp_ids />,<cms:pages masterpage='anfragen.php' custom_field="preis=<cms:show item />" ids_only='1' />" scope='global' />
<cms:set tmp_ids="<cms:show tmp_ids />,<cms:pages masterpage='anfragen.php' custom_field="lead_id=<cms:show item />" ids_only='1' />" scope='global' />
<cms:set tmp_ids="<cms:show tmp_ids />,<cms:pages masterpage='anfragen.php' custom_field="nachname=<cms:show item />" ids_only='1' />" scope='global' />
<cms:set tmp_ids="<cms:show tmp_ids />,<cms:pages masterpage='anfragen.php' custom_field="vorname=<cms:show item />" ids_only='1' />" scope='global' />
<!-- Cleaning the list of found ids with array_unique(), so every page is listed only once -->
<cms:set tmp_ids="<cms:php>echo trim(implode(',', array_unique(explode(',', '<cms:show tmp_ids />'))),',');</cms:php>" scope='global' />
<!-- The substrings should be connected with AND, so I use array_intersect() -->
<cms:if found_ids != ''>
<cms:set found_ids="<cms:php>echo trim(implode(',', array_intersect(explode(',', '<cms:show tmp_ids />'), explode(',', '<cms:show found_ids />'))),',');</cms:php>" scope='global' />
<cms:else/>
<cms:set found_ids=tmp_ids scope='global' />
</cms:if>
</cms:each>
<!-- Outputting the search result -->
<cms:pages masterpage='anfragen.php' id="<cms:show found_ids />" >
<tr id="<cms:show k_page_id />" ic-get-from="<cms:link masterpage='app/api.php' />anfragen/<cms:show k_page_id />/view" ic-target="#details">
<td><cms:show gewerk /></td>
<td><cms:php>echo str_replace(" ", " ", "<cms:show status />");</cms:php></td>
<td><cms:show datum_anfrage /></td>
<td><cms:show preis /></td>
<td><cms:show lead_id /></td>
<td><cms:show nachname />, <cms:show vorname /></td>
</tr>
</cms:pages>