{init_search_results} (ver4)
Init_search_results allows developers design their own search result pages. Since version 4.3.1
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.
Since 4.3.1 site search utilises MySQL's full-text search capabilities.
Parameters
- name - variable name where the returned data is saved.
- query - the search string, 4.6.4
- sites - comma separated list of sites from where the search is performed, use "all" for all sites. By default only the active site is searched, 4.6.4
- classes - defines the object classes.
- exclude - string the search results does not include, 4.6.4
- search_type - which search to perform: "or", "and" or "phrase", by default "or" is used, 4.6.4
- section - ID of the section from where the search is performed, 4.6.4
- last_changed - the last changed date of the object from where the search is performed, possible values are "1 day", "7 day", "1 month", "3 month", "6 month", "1 year", 4.6.4
- order - the order by which the search results are returned, possible values are "relevance", "title", "date". The "relevance" can be only used with fulltext searches. 4.6.4
- 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 **********}
For versions before 4.6.4
To create detailed searches in versions earlier than 4.6.4, use the 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
