The module I'm searching is News and I only want to find articles in the 'faq' or 'faq' child categories.
In the News module, create the following summary template. I've named it 'searchnewsfaqsummary':
Code: Select all
{if $items|count gt 0}
{assign var=newsids value='~'}
{foreach from=$items item=item}
{$newsids|cat:$item->id|cat:'~'}
{/foreach}
{/if}
Code: Select all
{strip}
<h3>{$searchresultsfor} "{$phrase}"</h3>
{if $itemcount > 0}
{capture assign=newsids}
{cms_module module=News category="faq*" summarytemplate='searchnewsfaqsummary'}
{/capture}
{foreach from=$results item=entry}
{assign var=modrecord value='~'|cat:$entry->modulerecord|cat:'~'}
{if $entry->module == 'News' and $newsids|strpos:$modrecord !== false}
<p><a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)</p>
{/if}
{/foreach}
{else}
<p><strong>{$noresultsfound} Try again</strong></p>
{cms_module module=Search modules='News' search_method="post"}
{/if}
{/strip}
- The Search module only makes one call to the News module so overhead is minimal.
- The news summary template creates a string something like ~12~ ~22~ ~37~
- The Search results template creates a variable {$modrecord} to which is prepended and appended a tilde ~ character to ensure each modrecord id string is unique
- The Search template then iterates through the $result list and compares the $modrecord (with ~ on both ends) to see if the same string appears in the captured News output.
- When a match is found, it outputs the Search result link
Please Note:
1. I changed the News template from the default {foreach from=$items item=entry} to {foreach from=$items item=item} to ensure it doesn't get confused with the Search $entry var.
2. While you can only have one Search result template, you can search and output results from multiple modules by refining the {if}{elseif}{else} statements to suit (and maybe adding eg 'and $page_alias eq 'faq'} or similar to narrow down the result set to get the correct results for a particular page.
It's not perfect but should get you by until the Search module passthru parameter is implemented.
Hope this helps
psy