The search loops and tags

SPIP is equipped with its own integrated internal search engine. It will therefore be necessary to construct a page to display the results of searches made by site visitors.

The search interface

In order to display the search form, you only need to insert the following tag:


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|spip.php?page=xxx)] [1]

where spip.php?page=xxx is the page that you would like to direct the site visitor to, and xxx.html is that page’s corresponding squelette template.

Historical note: In versions prior to SPIP 1.9, it was necessary to code this as xxx.php3 instead of spip.php?page=xxx

Up until SPIP 1.9, the URLs for pages generated by SPIP were of the form and not

The results squelette 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 since [SPIP 1.8.2], also for 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).

-  Introduced in [SPIP 1.5.1], the #RECHERCHE tag displays the query as formulated by the site visitor.

An example of a completed loop:

Highlighting the query in other pages [2]

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").

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:

The #DEBUT_SURLIGNE and #FIN_SURLIGNE tags as well as the customsiation variable $nombre_surligne are obsolete in SPIP 2.0.3 onwards.


[1from version 2 of SPIP onwards, it would be better to write #FORMULAIRE_RECHERCHE{#URL_PAGE{xxx}}

[2for versions prior to 2.0
#DEBUT_SURLIGNE, #FIN_SURLIGNE are two tags which tell SPIP in what part of the page it should colour the search keywords. These tags particular to the site are available at any point inside the squelette templates.

When the site visitor arrives on a page from the search results page, the keywords sought after are automatically coloured on the page that has been found and linked to. SPIP does not distinguish, for example, between a menu, a piece of JavaScript code or the text of the article itself, it will colour the words wherever they appear, which can be quite ugly sometimes and can even cause problems with script execution. So these two tags can be used to restrict this colouring behaviour to just a part of the displayed page. For example:

-  The customisation variable $nombre_surligne indicates the maximum number of times that a search keyword will be highlighted in the text. By default, its value is defined as 4.

Author George, Mark Published : Updated : 26/10/12

Translations : عربي, català, Deutsch, English, Español, français, italiano, Nederlands, українська