The search interface
In order to display the search form, you only need to insert the following tag:
#FORMULAIRE_RECHERCHE
By default, the form sends the requests to the spip.php?page=recherche
page; so you will therefore need to create a recherche.html
template file in order to display the results.
You can use another results page instead if you wish, which requires that you use tag with the following alternative syntax:
#FORMULAIRE_RECHERCHE{#URL_PAGE{xxx}}
where xxx
is the page that you would like to direct the site visitor to, and xxx.html
is that page’s corresponding template.
The results template file
The loops used for display the search results have, in fact, already been well described in the documentation here: ARTICLES, SECTIONS, NEWS ITEMS and the FORUMS. You can actually run searches on not only the articles, but also the sections, the news items and forum contents.
- The only difference compared to what is documented in the loops reference manual, is the choice of the selection criteria, which must be {recherche}
. The other display criteria and the tags usable inside the loops remain unchanged.
- However, in order to rank the results by their relevancy to the search criteria, it is recommended to prefer using the new display criteria: {par points}
. The results are generally displayed in decreasing order of their scores ({par points}{inverse}
), i.e. with the most relevant shown first.
- And finally, there is now also the #POINTS
tag, which displays the relevancy of the results (warning, shown in its raw numerical format, it is not of itself terribly informative, as it is primarily used only for sorting the results).
- The #RECHERCHE
tag displays the query as formulated by the site visitor.
An example of a completed loop:
<h1><:resultats_recherche:>[ (#RECHERCHE)]</h1>
<B_articles>
<h2><:info_articles_trouves:></h2>
<ul>
<BOUCLE_articles(ARTICLES) {recherche} {par points}{inverse}>
<li>#POINTS <a href="#URL_ARTICLE">#TITRE</a></li>
</BOUCLE_articles>
</ul>
</B_articles>
Highlighting the query in other pages
SPIP offers an option to underline the request within the pages, it must be activated by adding the following lines to the my_options.php file
define('_SURLIGNE_RECHERCHE_REFERERS',true);
To take advantage of highlighting the search terms right from the first display page (e.g. in the case where the search does not return the recherche.html) page, add this code into the mes_options.php file:
if (isset($_REQUEST['recherche'])) {
$_GET['var_recherche'] = $_REQUEST['recherche'];
}
Making the search terms stand out this way is done by using the jquery function library.
- If the recherche
variable is included in the URL, it is first cleaned to avoid any injection attacks, and then, if the search keyword is found directly inside a block tagged as class="surlignable"
(or in a descendant block of a class="surlignable"
block), it will be displayed as a highlight within a <span class="spip_surligne">.../span>
block.
- If it is found directly inside a class="pas_surlignable"
block (or in a descendant block of a class="pas_surlignable"
) block, it is displayed normally as (nohighlight).
- The visual appearance of the highlighting can be changed by modifying the style definition for .spip_surligne
(see: "Modifier l’habillage graphique").