init_search_results (ver4)

Version 4.3.1 and later

Init_search_results allows developers design their own search result pages.

NB! Due to site search re-design in the version 4.3.1 Saurus API tag {init_search_results} loses some backwards compability: most of the old parameters are deprecated, more convenient new parameters and attributes are available. Version upgrade checks against the possible backwards compability issues and dislpayes warnings during first step of upgrade.
Version 3 still uses old parameters.

Since 4.3.1 site search utilises MySQL's full-text search capabilities.

Parameters

  • name -  variable name where the returned data is saved.
  • classes - defines the object classes.
  • start - the starting row number to return.
  • limit - the number of rows to return. You must use this parameter always with "start" parameter. Start and limit work on all the found class types separately.

Attributes

  • title - class title
  • name - class name
  • count - the number of returned objects in that class.
  • counttotal - the total number of objects found, not affected by "limit" parameter.
  • results - list of objects found in that class, each result is object with following attributes:
    • id - the id number of the object
    • title - the title of the object
    • href - the link to object detailed view, e.g. ?id=368.
    • class - class name of the object
    • excerpt - if the object is article, then this is a excerpt from the article containing the first search term.

General tags

  • <name>_counttotal - the total number of objects found, not affected by "limit" parameter.

Example (See more detailed sample in template "extensions/saurus4/content_templates/search_results.html"):

{init_search_results name="search" start=0 limit=20}

{********* Search header **********}
<h1>You searched: {$smarty.request.query|xss_clean|htmlspecialchars}</h1>

Total results: {$search_counttotal}

<hr>

{********* Search results **********}
{foreach from=$search item="label"}
   {foreach from=$label->results item="object"}
     <h2><a href="{$object->href}&highlight={$smarty.request.query|replace:" ":","}">{$object->title}</a></h2>
     <p>{$object->excerpt}</p>
   {/foreach}
 {/foreach}

{********* // Search results **********}


Detailed searches

To create detailed searches use following variables with GET or POST method when submitting search queries:
  • section, section ID constraints the search to that section (includes all subsections),
    NB! this was named "cat" before version 4.3.1
  • exclude, words not in search results
  • bool, perform query using or, and or phrase search, defaults to or
  • order, sorting order of search results, date: newest objects first, title: alphabetical order by object title, relevance: MySQL full-text search score

init_search_results (ver3)

Init_search_results allows developers design their own search result pages. Since version 3.2.8.

Parameters
  • name -  variable name where the returned data is saved. 
  • amount_of_pages - defines how many page links are displayed in the paging list.
  • pagenum_separator - the character that separates the page number in the paging list
  • pagenum_next_chr - the character (string) for the link to the next product list's page
  • pagenum_prev_chr - the character (string) for the link to the previous product list's page
  • pagenum_link_class - the CSS-class for the links in the paging list
  • pagenum_numbers_style - the CSS-class for the numbers in the paging list
  • page_seq -
Elements
  • .link - prints the URL to the found object.
  • .link_target - prints the target of the result.
  • .title - prints the title of the found object.
  • .lead - prints the lead of the found object.
General tags
  • <name>_pages - prints the default paging list.
  • <name>_pages_custom - prints the custom paging list.
  • <name>_next_pages - prints the link to the next pages in the paging list.
  • <name>_previous_pages - prints the link to the previous pages in the paging list.
  • <name>_string - prints the search string.
  • <name>_count - prints the total count of the found objects.
  • <name>_pages_count - prints the total count of the pages of the found objects.
  • <name>_objects - array of the found objects. 
  • <name>_labels - array of the allowed types (labels) for search.
  • t_name - prints the name of the label (type of the results).
  • is_active - equals 1 if current label is active.
  • is_disabled - equals 1 if current label is disabled.
  • type_id -  prints the class type id of the label.

To build use your own search results template, place the following code in your page template:

{if $smarty.get.otsi} {* or $smarty.post.otsi *}
  {print_content tpl="search_results"}
 {else}
  {print_content}
 {/if}

Examples

{init_search_results page_seq=1 pagenum_separator=" " amount_of_pages=3 pagenum_next_chr="<b>&#8250;</b>" pagenum_prev_chr="<b>&#8249;</b>"}

{******************* Search labels ********************}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
 <td>
  <table border="0" cellspacing="0" cellpadding="0">
  <tr>
   <td background="{$img_path}/otsing_taust.gif"><img src="px.gif" width="7" height="7"></td>
 {foreach from=$search_labels item=label}
  {* Found results AND label is active *}
  {if $label.is_active AND ! $label.is_disabled}
   <td><img src="{$img_path}/tab_on_left.gif" width="10" height="19"></td>
   <td background="{$img_path}/tab_taust.gif" class="tabOn">{$label.t_name}</td>
   <td><img src="{$img_path}/tab_on_right.gif" width="10" height="19"></td>
  {* No result: label disabled*}
  {elseif ! $label.is_active AND $label.is_disabled}
   <td><img src="{$img_path}/tab_off_left.gif" width="10" height="19"></td>
   <td background="{$img_path}/tab_off_taust.gif" class="deadTab">{$label.t_name}</td>
   <td><img src="{$img_path}/tab_off_right.gif" width="10" height="19"></td>
  {* Found results AND label is inactive*}
  {else}<BR>   <td><ahref="?otsi={$search_string}&tyyp_id={$label.type_id</FONT>}&lk=1"><imgsrc="{$img_path}/tab_off_left.gif"width="10"height="19"border="0"></a></td><BR>   <tdbackground="{$img_path}/tab_off_taust.gif"class="tabOff"><ahref="?otsi={$search_string}&tyyp_id= {$label.type_id}&lk=1" class="link_tab_off">{$label.t_name}</a></td>
   <td><ahref="?otsi={$search_string}&tyyp_id={$label.type_id}&lk=1"><img src="{$img_path}/tab_off_right.gif" width="10" height="19" border="0"></a></td>
  {/if}
 {/foreach}
  </tr>
  </table>
 </td>
 <td width="100%" background="{$img_path}/otsing_taust.gif"></td>
</tr>
</table>
{*******************// Search labels ********************} <br>
<span class="plk">{sysword word="Results" type="Search"}</span>
{if $search_count}
<br>
{else}
<br><br>
<table border="0" cellpadding="1" cellspacing="0" class="teade" bgcolor="#686868" width="100%">
<tr>
 <td>
  <table border="0" cellpadding="10" cellspacing="0" class="teade" bgcolor="#FFFFFF" width="100%">
   <tr>
    <td> No results!</td>
   </tr>
  </table>
 </td>
</tr>
</table>
{/if}
<br>
{sysword word="Keyword" type="Search"}: &quot;<strong>{$search_string}</strong>&quot;, {sysword word="Results" type="Search"} <strong>{$search_count}</strong><br>
{if $search_count}
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EDEDED">
 <tr>
  <td><img src="{$img_path}/px.gif"></td>
 </tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="lehed">
 <tr>
  <td align="center" class="txt">
  {if $search_pages_custom}
   {*******************Paging********************}<BR>   <ahref="?lk=1&otsi={$search_string}&tyyp_id={$search_tyyp_id}"><b>&laquo;</b></a>{$search_previous_pages}{$search_pages_custom}{$search_next_pages}<ahref="?lk={$search_pages_count}&otsi={$search_string}&tyyp_id={$search_tyyp_id}"><b>&raquo;</b></a>
   {******************* //Paging ********************}   {else}
   1-{$search_count}
  {/if}
  </td>
 </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EDEDED">
 <tr>
  <td><img src="{$img_path}/px.gif"></td>
 </tr>
</table>
{******************* Results ********************}
<ol start={$search_start_pos}>
{foreach from=$search_objects item=obj}
 <li>
  <a href="{$obj.link}" {$obj.link_target}><strong>{$obj.pealkiri}</strong></a><br>
  <span class="otsingutulemus">{$obj.sisu}</span>
  <br><br>
 </li>
{/foreach}
</ol>
{******************* // Results ********************}
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EDEDED">
 <tr>
  <td><img src="{$img_path}/px.gif"></td>
 </tr>
</table>
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="lehed">
 <tr>
  <td align="center" class="txt">
  {if $search_pages_custom}
   {*******************Paging********************}<BR>   <ahref="?lk=1&otsi={$search_string}&tyyp_id={$search_tyyp_id}"><b>&laquo;</b></a>{$search_previous_pages}{$search_pages_custom}{$search_next_pages}<ahref="?lk={$search_pages_count}&otsi={$search_string}&tyyp_id={$search_tyyp_id}"><b>&raquo;</b></a>
   {******************* //Paging ********************}
  {else}
   1-{$search_count}
  {/if}
  </td>
 </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EDEDED">
 <tr>
  <td><img src="{$img_path}/px.gif"></td>
 </tr>
</table>
{/if}