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

mSearch2

Snippet for search and output.

In the work pdoTools is used, so all basic options are available: TV connection, requirement reference in &where, &select, etc. Basically this snippet represents modified pdoResources with two distinctions:

  • It uses search and add placeholder [[+weight]] with points for output.
  • Also it adds placeholder [[+intro]] with matches highlighted.

Snippet is supposed to react to transferred request, so it is highly recommended to involve it uncaсhed.

Options

NameBy defaultDescription
&tpltpl.mSearch2.rowChunk layout for every outcome. Usual resource placeholders + [[+weight]] and [[+intro]].
&returnIdsfalseTo return id list of proper pages with a comma.
&showLogfalseTo show extra information on snippet work. For the authorized in «mgr» context only.
&limit10Limit of the result selection.
&offset0Result offset from the beginning of selection.
&depth10In-depth search of resources for every parent.
&outputSeparator\nOptional string for separating results of work.
&toPlaceholderUnless it is empty, snippet will keep all data in placeholder with the name instead of displaying.
&parentsList of categories with a comma for the output restriction.
&includeTVsTV options list for selection with a comma. For example: «action,time» will provide [[+action]] and [[+time]].
&tvPrefixPrefix for TV placeholders, for example «tv.».
&whereAdditional selection options coded in JSON.
&showUnpublishedfalseTo show unpublished products.
&showDeletedfalseTo show remote resources.
&showHiddentrueTo show resources hidden in menu.
&hideContainersfalseTo hide resources-containers.
&introCutBefore50Specify number of symbols for the output in placeholder [[+intro]] before the first coincidence in the text.
&introCutAfter250Specify number of symbols for the output in placeholder [[+intro]] after the first coincidence in the text.
&htagOpen<b>Opening tag for highlighting of the found results in [[+intro]].
&htagClose</b>Closing tag for highlighting of the found results in [[+intro]].
&parentsVarparentsVariable name for extra filtration on parents. You can send it through $_REQUEST.
&queryVarqueryVariable name for getting search request from $_REQUEST.
&tplWrapperChunk-wrapper for wrapping all the results. Recognizes the placeholders:[[+output]], [[+total]], [[+query]] and [[+parents]].
&wrapIfEmptyfalseIncludes chunk-wrapper output &tplWrapper even though there are no results.
&forceSearchtrueBinding search for output. If there is no one - no output.
&minQuery3Minimal length of the search query.
&fieldsSystem settings redefinition of weight for indexed fields with comma: &fields=pagetitle:5,content:3,comment:1,tv_mytvname:2. mse2_index_fields is used by default.
&showSearchLogfalseTo show detailed information on given points of resource search when inserting &showLog.

Lexicons

Snippet may display search errors messages which change in system dictionaries.

  • mse2_err_no_results → "No results found".
  • mse2_err_min_query → "Search query is too short". That means the query is less than the &minQuery value.
  • mse2_err_no_query → "Search query is empty".

There you can also find other records used in chunks and snippets by default.

Search form

Snippet must have search query in the array $_REQUEST for it to work. It can be sent by simplest form:

modx
<form action="/search.html" method="get">
  <input type="text" name="query" value="[[+mse2_query]]" />
  <button type="submit">Искать!</button>
</form>

Note that the query should be referred under the same name as specified in the parameter &queryVar, query by default.

Examples

If empty action is specified, it is transferred to the current page.

modx
<form action="" method="get">
  <input type="text" name="query" value="[[+mse2_query]]" />
  <button type="submit">Искать!</button>
</form>

[[!mSearch2]]

You can use pages breakdown via pdoPage. mSearch2 sets pdoTools automatically, so you have already got pdoPage.

modx
<form action="" method="get">
  <input type="text" name="query" value="[[+mse2_query]]" />
  <button type="submit">Искать!</button>
</form>

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

[[!+page.nav]]

Snippet can be caused along with mSearchForm

modx
[[!mSearchForm]]

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

[[!+page.nav]]

You can also use mSearch2 to search and output together with msProducts:

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

[[!+page.nav]]

returnIds parameter specifies msProducts - found products list for the output. And the default filter substitutes misssing id when nothing is found, otherwise msProducts will output every row at a time.

In that case you can use all the fields of the products in the chunk processing.