Skip to content
  1. Extras
  2. mSearch2
  3. Snippets
  4. mSearch2

mSearch2

Snippet for search and output of results.

Uses pdoTools, so it supports TV, &where, &select, etc. In practice it is a modified pdoResources with two additions:

  • It uses search for results and adds placeholder [[+weight]] with relevance score.
  • It adds placeholder [[+intro]] with highlighted matches.

The snippet depends on the query from the request, so call it uncached.

Parameters

NameDefaultDescription
&tpltpl.mSearch2.rowChunk for each result. Standard resource placeholders plus [[+weight]] and [[+intro]].
&returnIdsfalseReturn only comma-separated IDs of matching pages.
&showLogfalseShow extra snippet debug info. Only for authenticated users in mgr context.
&limit10Max results.
&offset0Skip results from the start.
&depth10Search depth from each parent.
&outputSeparator\nOptional separator between results.
&toPlaceholderIf set, output is saved to this placeholder instead of printed.
&parentsComma-separated parent IDs to limit results.
&includeTVsComma-separated TV names to load, e.g. "action,time" → [[+action]], [[+time]].
&tvPrefixPrefix for TV placeholders, e.g. "tv.".
&whereExtra query conditions as JSON.
&showUnpublishedfalseInclude unpublished resources.
&showDeletedfalseInclude deleted resources.
&showHiddentrueInclude menu-hidden resources.
&hideContainersfalseExclude container resources.
&introCutBefore50Characters before first match in [[+intro]].
&introCutAfter250Characters after first match in [[+intro]].
&htagOpen<b>Opening tag for highlights in [[+intro]].
&htagClose</b>Closing tag for highlights in [[+intro]].
&parentsVarparentsRequest variable name for parent filter.
&queryVarqueryRequest variable name for search query.
&tplWrapperWrapper chunk. Placeholders: [[+output]], [[+total]], [[+query]], [[+parents]].
&wrapIfEmptyfalseOutput wrapper chunk even when there are no results.
&forceSearchtrueRequire a search query; output nothing without it.
&minQuery3Minimum query length.
&fieldsOverride indexed field weights, e.g. pagetitle:5,content:3,comment:1. Default: mse2_index_fields.
&showSearchLogfalseShow detailed search scoring when &showLog is on.

Lexicons

Search error messages are in system lexicons:

  • mse2_err_no_results → "No matching results".
  • mse2_err_min_query → "Search query too short" (shorter than &minQuery).
  • mse2_err_no_query → "Empty search query".

Other default chunk/snippet strings are there too.

Lexicons

Search form

The snippet needs the search query in $_REQUEST. A simple form:

modx
<form action="/search.html" method="get">
  <input type="text" name="query" value="[[+mse2_query]]" />
  <button type="submit">Search!</button>
</form>

The query must use the name from &queryVar (default query).

Examples

Empty action submits to the current page:

modx
<form action="" method="get">
  <input type="text" name="query" value="[[+mse2_query]]" />
  <button type="submit">Search!</button>
</form>

[[!mSearch2]]

Pagination with pdoPage. mSearch2 installs pdoTools, so pdoPage is available:

modx
<form action="" method="get">
  <input type="text" name="query" value="[[+mse2_query]]" />
  <button type="submit">Search!</button>
</form>

[[!pdoPage?
  &element=`mSearch2`
]]

[[!+page.nav]]

With mSearchForm:

modx
[[!mSearchForm]]

[[!pdoPage?
  &element=`mSearch2`
]]

[[!+page.nav]]

Search and output products with msProducts:

modx
[[!pdoPage?
  &element=`msProducts`
  &parents=`0`
  &resources=`[[!mSearch2:default=`999999`?returnIds=`1`&limit=`0`]]`
  &sortby=`ids`
]]

[[!+page.nav]]

returnIds gives msProducts the list of found product IDs. The default filter uses a non-existent ID when nothing is found so msProducts does not list all products.

You can use all product fields in the output chunk.