Simplesearch modx revo parameters. We press the button "Download add-ons"

Hello dear friends and colleagues! I want to acquaint you with an excellent package for organizing a search on the site under the system Modx revolution- SimpleSearch... I will explain to you step by step how to install this package on a site and organize a search on the site. So let's get started:

1. First, go to "System" - "Package Management"

2. We press the button "Download add-ons"

3. We drive into the search bar - SimpleSearch, press "Enter" and click on the "Download" button

4. The package will download

5. Click on "Package Management"

6. And click the "install" button next to the SimpleSearch downloaded by us

Click "Continue" and then "OK"

7. Create a new resource at the root of the tree

Title: Search results, put a tick "Do not show in the menu". Click on the "Settings" tab and uncheck "Searchable", "Use HTML Editor". Unforgettable to save the resource.

8. Next, go to the newly created resource and enter

[[! SimpleSearch]]

9. Remember the id of this resource, this is the page for displaying search results

In the template where the search form itself is located, insert the following code:

[[! SimpleSearchForm? & landing = `1` & tpl =` search`]]

where landing is the ID of the search results display page, and the search chunk is responsible for the search form itself, which we will now create

10. Then copy the following code

this is the content of the file core / components / simplesearch / elements / chunks / searchform.chunk.tpl:

into a new chunk called search and create the template for displaying the search window that we need.

11. Next, we solve the problems with the encoding

Find the file core / components / simplesearch / model / simplesearch / simplesearch.class.php in it, replace the line

$ text = trim (preg_replace ("/ \ s + /", "", $ this-> sanitize ($ text)));

$ text = trim (preg_replace ("/ \ s + / u", "", $ this-> sanitize ($ text)));

12. Then we replace the line

$ string = preg_replace ("/". $ quoteValue. "/ i", "<".$tag." class=".$cls.">$0", $ string);

$ string = preg_replace ("/". $ quoteValue. "/ iu", "<".$tag." class=".$cls.">$0", $ string);

13. And also replace the line

$ text = preg_replace ("/(\ {\ {\+.*?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\use\\\\\\\\\\\") \\\\\\\\\\\\\\ ", \\" ", $ text);

$ text = preg_replace ("/(\ {\ [\+.*?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

14. And the last thing, you need to comment out the line

if (! empty ($ str)) $ this-> searchString = strip_tags ($ this-> modx-> sanitizeString ($ str));

Basic SimpleSearch chunks

The search on the site powered by Modx Revolution is ready. It works, you can see for yourself, but there are a few more points that will come in handy when working with this snippet. Namely, editing chunks of search results, its wrapper, pagination, and so on. First, you need to understand that all chunks in the .tpl format are located along this path: core / components / simplesearch / elements / chunks /. Well, in order to make it easier to work with them, we will display the main chunks in the Modx admin panel. Here are their parameters

  • containerTpl
  • pageTpl
  • currentPageTpl

Well, we will call the chunks themselves whatever we want.

Tpl parameter - chunk SimpleSearchResult

Parameter tpl is responsible for displaying each individual item in the search result. Let's create a chunk and name it SimpleSearchResult... Let's copy the code from the file into it core / components / simplesearch / elements / chunks / searchresult.chunk.tpl:

[[+ idx]]. partial andTerms Do I need to add logical AND between words. 1 matchWildcard Enable wildcard search.Set to false to accurately search the search term. 1 docFields List of individual document fields to search for. pagetitle,
longtitle,
description,
introtext,
alias,
, content fieldPotency Evaluating and sorting results perPage Number of search results for one page. 10 showExtract Whether to show a cut of the content of each search result. 1 extractSource Allows the user to define where the checkout comes from.If the value of this parameter is the name of the resource field (including TV if & includeTVs is set), then this resource field is used for the extract.Otherwise, the parameter is taken as the name of the fragment being executed.The fragment is passed by the resource array as parameters.If this name does not have a fragment, then the extract will be empty. content extractLength The number of characters to extract from the content for each result. 200 extractEllipsis The string used to wrap the extraction results.The default is ellipsis.includeTVs Indicates whether TemplateVar values ​​should be included in the properties available for each resource template.The default is 0. Enabling this option may slow you down if you have many TVs. 0 processTVs Indicates whether TemplateVar values ​​should be rendered as they would on the summarized resource.The default is 0. Some notes: toTV can be accessed by your TV name [[+ myTV]] By default, SimpleSearch does not use a prefix, eg [[+ tv.myTV]] will NOT be displayed.
TVs are processed during indexing for Solr searches, so there is no need to do that here. 0 highlightResults Specify or not highlight the search term in the results. 1 highlightClass The name of the CSS class to add to the highlighted conditions in the results. sisea-highlight highlightTag An html tag to wrap the highlighted term in search results. span pageTpl The part used to link to pages. PageLink currentPageTpl The block used for the current link on the page. CurrentPageLink pagingSeparator Separator (separator) for use between page links. | ids List of document IDs, separated by commas, to limit the search idType The type of restriction for the ids parameter. If parents, then all elements of identifiers will be added to the ids parameter for search. If documents, only the specified identifiers will be used in the search. parents exclude List of resource identifiers, separated by commas, to exclude from the search, for example. "10,15,19". This excludes resources with identifiers "10", "15", or "19". depth If idtype is set to parent, the depth down the resource tree to look for with the specified IDs. 10 hideMenu Do I need to return Resources that have hidemenu. 0 shows only visible resources, 1 shows only hidden resources, 2 shows both. 2 contexts Search contexts. The default is the current context if none are explicitly specified. searchIndex The name of the REQUEST parameter to be used by the search. search offsetIndex The name of the REQUEST parameter used for page offset. sisea_offset placeholderPrefix The prefix for global placeholders, as specified by the snippet. sisea. toPlaceholder Whether to set the output for direct return, or set to a placeholder with the name of this property. urlScheme Required url scheme: http, https, full, abs, relative, etc. See documentation $ modx-> makeUrl (). This is used when pagination links are generated. customPackages Set to search for custom tables by downloading their package. See below for details. postHooks A comma-listed list of launch hooks that can add faceted sets to end results. activeFacet The current active face. Leave this alone if you don't want the result to show up from a non-standard aspect retrieved via postHook. default facetLimit The number of non-active-facet results to display on the main results page. 5 sortBy A comma-separated list of resource fields to sort the results. Leave blank to sort by relevance and rating. sortDir A comma-separated list of instructions for sorting results. Must match the number of items in the sortBy parameter. DESC noResultsTpl Chunk to use if no search results are found.

Implementing search on the MODX website

1. SimpleSearch

2. We solve various problems with encodings, etc.

Go to core / components / simplesearch / model / simplesearch / simplesearch.class.php in it, replace the following lines:

line 297:

$ text = preg_replace ("/(\ {\ {\+.*?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\use\\\\\\\\\\\") \\\\\\\\\\\\\\ ", \\" ", $ text);

replace with

$ text = preg_replace ("/(\ {\ [\+.*?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

line 311:

$ text = trim (preg_replace ("/ \ s + /", "", $ this-> sanitize ($ text)));

replace with

$ text = trim (preg_replace ("/ \ s + / u", "", $ this-> sanitize ($ text)));

line 413:

$ string = preg_replace ("/". $ quoteValue. "/ i", "<".$tag." class="".$cls."">$0", $ string);

replace with

$ string = preg_replace ("/". $ quoteValue. "/ iu", "<".$tag." class="".$cls."">$0", $ string);

Let's comment out line 179:

If (! Empty ($ str)) $ this-> searchString = strip_tags ($ this-> modx-> sanitizeString ($ str));

those. it should look like this

/ * if (! empty ($ str)) $ this-> searchString = strip_tags ($ this-> modx-> sanitizeString ($ str)); * /

3. Make copies of all standard chunks which are located in the core / components / simplesearch / elements / chunks / directory

We create new chunks with the same names and the -new prefix, and the same content (only they are no longer based on files, but ordinary ones), for which you will understand all this further.

For example, let's take the first chunk currentpagelink.chunk.tpl and create a new chunk currentpagelink-new(elements - create a new chunk) and transfer the code into it.

[[+ text]]

Responsible for managing the button in pagination for the active page.

And in the same way, we create the rest of the chunks:

- pagelink-new- is responsible for displaying a separate pagination button.

[[+ text]]

  • [[+ link]]- link overdocument
  • [[+ text]]- Document Number

- searchform-new- search form

searchnoresults you can not transfer it - there is not any design;

searchresult-new- output of each item of the result.

[[+ idx]]. [[+ pagetitle]]

[[+ extract]]

  • [[+ idx]]- the number of the search result in the list
  • [[+ link: is = '': then = `[[~ [[+ id]]]]`: else = `[[+ link]]`]]
  • [[+ longtitle]]- extended title
  • [[+ pagetitle]]- title
  • [[+ extract]]- the text by which this document was found

searchresultli- in fact, you can also not transfer.

searchresults-new- wrapper all results

[[+ resultInfo]]

[[+ paging]]
[[+ results]]
[[% sisea.result_pages? & namespace = `sisea` & topic =` default`]][[+ paging]]

  • [[+ resultInfo]]- information about the number of found documents and by what phrase.
  • [[+ sisea.result_pages? & namespace = `sisea` & topic =` default`]]

    Phrase output "Search Results Pages:"

  • [[+ paging]]- pagination
  • [[+ results]]- searching results

After all that has been done, you should have 5 new chunks.

4. Create a new document to which the search results will be displayed

Title: Search results, check the box "Do not show in the menu". In "Settings" and remove the checkboxes from "Available for search", "Use HTML editor". We save. Refresh the page and add it to the content

[[! SimpleSearch? & tpl = `searchresult-new` & containerTpl =` searchresults-new` & pageTpl = `pagelink-new` & currentPageTpl =` currentpagelink-new`]]

design chunks that were created in step 3 (appearance).

If you want pictures in the search results, then add at the end of this output

& includeTVs = `1` & processTVs =` 1`

In the searchresult chunk, the image can be called like this: [[+ img]].

5. Displaying the search form

At the place where you need to display the search form, write

[[! SimpleSearchForm? & landing = `11` & tpl =` searchform-new`]]

Here landing is the id of the page with the search results, in tpl - the form design chunks that were created in step 3.

We took steps 4 and 5 so that you could edit the external design at your discretion: the form itself, search results, etc. without getting into the source code. And the standard design is rather sad, this is how the standard search form looks like, for example.

6. We change the design.

I don't see the point in describing how to arrange all chunks, for example I will give a new design for a chunk searchform-new

This is the usual standard bootstrap 3 form markup, on the site it looks like this:

Official documentation here: docs.modx.com/extras/revo/simplesearch

If you have any questions, write them in the comments.

SimpleSearch is a standard package, site search in modx revolution. We will add to it ajax request for live search. An example can be found on the same site, it works quite simply and, mind you, with pagination. The SimpleSearchForm snippet (search form) asks for an ajax request from a separate results page, which displays the SimpleSearch snippet.

1 Download the popular site search package SimpleSearch from the modx revo repository and install it.
We create a resource with an empty template so that ajax would take data and send it when requested in the search form.
For example, let's call the pseudo-results "search-results" it will be accessed by ajax.
Resource content:

search results [[! SimpleSearch]]

2 Now we will place the search form in a convenient place for you, the "SimpleSearchForm" snippet is responsible for this.
As a rule, the search form is shoved into modx templates.
The div element outputs the results of the ajax request.

[[! SimpleSearchForm]]

3 Let's connect ajax to send requests from the form to the page we created in step 1.
(!) Don't forget to include jquery
(!) Make sure at what address ajax is accessing the resource. The load () method is responsible for this in 2 places.

// SimpleSearch ajax $ (document) .ready (function () (// Button $ (". Sisea-search-form"). Submit (function () (// uncomment if button is needed // $ ("# site- search-results "). load (" / search-results / ", $ (". sisea-search-form "). serialize ()). slideDown (" fast "); return false;)); // Live search $ (". sisea-search-form input"). keyup (function () (if (this.value.length> 2) (// User types more than 2 characters in the search string // hides / displays results outside the window $ (document) .click (function (event) (// hide if ($ (event.target) .closest (". site-search-results"). length) return; $ (". site-search-results" ) .slideUp ("fast"); //event.stopPropagation ();)); $ ("# search"). click (function () (// display $ (". site-search-results"). slideDown ("fast"); return false;)); // ajax request loading search results from the page and showing the container $ ("# site-search-results"). load ("/ search-results /", $ (". sisea-search-form "). serialize ()). slideDown (" fast ");) else (// If typ less than 2 characters early, hide container (CSS display: none;) $ ("# site-search-results"). slideUp ("fast"); ))); ));

4 We include css for displaying the ajax effect of hiding and revealing the window and its necessary display styles, all to a minimum. Finish the rest of the styles yourself as described in the SimpleSearch package manual in modx revolution.

/ * SimpleSearch ajax * / .site-search-results (display: none; position: absolute; text-align: left; padding: 15px; background: # F7F7F7; border-radius: 5px; -webkit-border-radius: 5px ; -moz-border-radius: 5px; box-shadow: 2px 3px 9px -2px rgba (50, 50, 50, 0.55); -webkit-box-shadow: 2px 3px 9px -2px rgba (50, 50, 50, 0.55); -moz-box-shadow: 2px 3px 9px -2px rgba (50, 50, 50, 0.55);)

The search button in the SimpleSearchForm snippet can be removed altogether
since ajax already intercepts pressing the Enter button.

This snippet displays search results based on the search criteria sent.

Usage

Simply place the snippet in the Resource you would like to display search results in.

[[! SimpleSearch]]

Available Properties

Name Description Default
tpl The chunk that will be used to display the contents of each search result. SearchResult
containerTpl The chunk that will be used to wrap all the search results, pagination and message. SearchResults
useAllWords If true, will only find results with all the specified search words. 0
maxWords The maximum number of words to include in the search. Only applicable if useAllWords is off. 7
minChars The minimum number of characters to trigger the search. 3
searchStyle To search either with a "partial" LIKE search, or a relevance-based "match" search. partial
andTerms Whether or not to add a logical AND between words. 1
matchWildcard Enable wildcard search. Set to false to do exact searching on a search term. 1
docFields A comma-separated list of specific Resource fields to search. pagetitle, longtitle, alias, description, introtext, content
fieldPotency Score and sort the results (see https://github.com/splittingred/SimpleSearch/pull/29 for more infos / usage)
perPage The number of search results to show per page. 10
showExtract Whether or not to show an extract of the content of each search result. 1
extractSource (new in version 1.9) Allows the user to define where the extract comes from. If the value of this parameter is a resource field name (including TVs if & includeTVs is set) then that resource field is used for the extract. Otherwise the parameter is taken as the name of a Snippet to run. The Snippet is passed the resource array as parameters. If there is no Snippet by that name, then the extract will be empty. content
extractLength The number of characters for the content extraction of each search result. 200
extractEllipsis The string used to wrap extract results with. Defaults to an ellipsis. ...
includeTVs Indicates if TemplateVar values ​​should be included in the properties available to each resource template. Defaults to 0. Turning this on might make your search slower if you have lots of TVs. 0
includeTVList An optional comma-delimited list of TemplateVar names to include explicitly if includeTVs is 1.
process TVs Indicates if TemplateVar values ​​should be rendered as they would on the resource being summarized. Defaults to 0. Some notes:
TVs can be accessed by their TV name [[+ myTV]] By default SimpleSearch does not use a prefix, e.g. [[+ tv.myTV]] will NOT render. TVs are processed during indexing for Solr searching, so there is no need to do this here.
0
highlightResults Whether or not to highlight the search term in results. 1
highlightClass The CSS class name to add to highlighted terms in results. simplesearch-highlight
highlightTag The html tag to wrap the highlighted term with in search results. span
pageTpl The chunk to use for a pagination link. PageLink
currentPageTpl The chunk to use for the current pagination link. CurrentPageLink
pagingSeparator The separator to use between pagination links.
ids A comma-separated list of IDs to restrict the search to.
idType The type of restriction for the ids parameter. If parents, will add all the children of the IDs in the ids parameter to the search. If documents, will only use the specified IDs in the search. parents
exclude A comma-separated list of resource IDs to exclude from search eg. "10,15,19". This will exclude the resources with the ID "10", "15" or "19".
depth If idtype is set to parents, the depth down the Resource tree that will be searched with the specified IDs. 10
hideMenu Whether or not to return Resources that have hidemenu on. 0 shows only visible Resources, 1 shows only hidden Resources, 2 shows both. 2
contexts The contexts to search. Defaults to the current context if none are explicitly specified.
searchIndex The name of the REQUEST parameter that the search will use. search
offsetIndex The name of the REQUEST parameter to use for the pagination offset. simplesearch_offset
placeholderPrefix The prefix for global placeholders set by this snippet. simplesearch.
toPlaceholder Whether to set the output to directly return, or set to a placeholder with this propertys name.
urlScheme The URL scheme you want: http, https, full, abs, relative, etc. See the $ modx-> makeUrl () documentation. This is used when the pagination links are generated.
customPackages Set to search custom tables by loading their package. See below for more details.
postHooks A comma-separated list of hooks to run that can add faceted sets to the end results.
activeFacet The current active facet. Leave this alone unless you want a result to show from a non-standard facet derived through a postHook. default
facetLimit The number of non-active-facet results to show on the main results page. 5
sortBy A comma-separated list of Resource fields to sort the results by. Leave blank to sort by relevance and score.
sortDir A comma-separated list of directions to sort the results by. Must match the number of items in the sortBy parameter. DESC
noResultsTpl The chunk to use when no search results are found.

SimpleSearch Chunks

There are 4 chunks that are processed in SimpleSearch. Their corresponding SimpleSearch parameters are:

  • tpl - The Chunk to use for each result displayed.
  • containerTpl - The Chunk that will be used to wrap all the search results, pagination and message.
  • pageTpl - The Chunk to use for a pagination link.
  • currentPageTpl - The Chunk to use for the current pagination link.

Searching Custom Tables

Searching custom tables is available in SimpleSearch using the & customPackages property; however, you must have a custom package built for it. The format is:

ClassName: fieldName (s): packageName: packagePath: joinCriteria || class2Name: fieldName (s): package2Name: package2Path: join2Criteria

In other words, each custom package is separated by ||. Then, each part of it is separated by colons (:). An example to search Quip comments:

& customPackages = `quipComment: body: quip: (core_path) components / quip / model /: quipComment.resource = modResource.id`

Let "s break down each part:

  • className- The class name of the table you want to search. Here, it's QuipComment.
  • fieldName (s)- A comma-separated list of column names to search. We did "body", you could also have done "body, email" or whatever.
  • packageName- The name of the schema Package to add. This one is called quip.
  • packagePath- The path to the model / directory where the package is located.
  • joinCriteria- The SQL to join the table you want to search and the modResource table. Your table must have some connection to the Resource it "s on (otherwise SimpleSearch won" t know how to load a URL for it!)

Once you "ve added it, it will search those fields as well for data. If it finds it in that table, it will display the result as a link to the Resource you specified in your joinCriteria. In our example, that would be the resource the Quip comment is located on.

Hello dear friends and colleagues! I want to acquaint you with an excellent package for organizing a search on the site under the system Modx Revolution - SimpleSearch... I will explain to you step by step how to install this package on a site and organize a search on the site. So let's get started:

1. First, go to "System" - "Package Management"

2. We press the button "Download add-ons"

3. We drive into the search bar - SimpleSearch, press "Enter" and click on the "Download" button

4. The package will download

5. Click on "Package Management"

6. And click the "install" button next to the SimpleSearch downloaded by us

Click "Continue" and then "OK"

7. Create a new resource at the root of the tree

Title: Search results, put a tick "Do not show in the menu". Click on the "Settings" tab and uncheck "Searchable", "Use HTML Editor". Unforgettable to save the resource.

8. Next, go to the newly created resource and enter

[[! SimpleSearch]]

9. Remember the id of this resource, this is the page for displaying search results

In the template where the search form itself is located, insert the following code:

[[! SimpleSearchForm? & landing = `1` & tpl =` search`]]

where landing is the ID of the search results display page, and the search chunk is responsible for the search form itself, which we will now create

10. Then copy the following code

this is the content of the file core / components / simplesearch / elements / chunks / searchform.chunk.tpl:

into a new chunk called search and create the template for displaying the search window that we need.

11. Next, we solve the problems with the encoding

Find the file core / components / simplesearch / model / simplesearch / simplesearch.class.php in it, replace the line

$ text = trim (preg_replace ("/ \ s + /", "", $ this-> sanitize ($ text)));

$ text = trim (preg_replace ("/ \ s + / u", "", $ this-> sanitize ($ text)));

12. Then we replace the line

$ string = preg_replace ("/". $ quoteValue. "/ i", "<".$tag." class=".$cls.">$0", $ string);

$ string = preg_replace ("/". $ quoteValue. "/ iu", "<".$tag." class=".$cls.">$0", $ string);

13. And also replace the line

$ text = preg_replace ("/(\ {\ {\+.*?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\use\\\\\\\\\\\") \\\\\\\\\\\\\\ ", \\" ", $ text);

$ text = preg_replace ("/(\ {\ [\+.*?\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

14. And the last thing, you need to comment out the line

if (! empty ($ str)) $ this-> searchString = strip_tags ($ this-> modx-> sanitizeString ($ str));

Basic SimpleSearch chunks

The search on the site powered by Modx Revolution is ready. It works, you can see for yourself, but there are a few more points that will come in handy when working with this snippet. Namely, editing chunks of search results, its wrapper, pagination, and so on. First, you need to understand that all chunks in the .tpl format are located along this path: core / components / simplesearch / elements / chunks /. Well, in order to make it easier to work with them, we will display the main chunks in the Modx admin panel. Here are their parameters

  • containerTpl
  • pageTpl
  • currentPageTpl

Well, we will call the chunks themselves whatever we want.

Tpl parameter - chunk SimpleSearchResult

Parameter tpl is responsible for displaying each individual item in the search result. Let's create a chunk and name it SimpleSearchResult... Let's copy the code from the file into it core / components / simplesearch / elements / chunks / searchresult.chunk.tpl:

Related publications