• The package will be downloaded

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

    1. First, go to “System” - “Package Management”

    2. Click the "Download add-ons" button

    3. Type in the search bar - SimpleSearch, press "Enter" and click on the "Download" button

    4. The package will be downloaded

    5. Click "Manage packages"

    6. And click the “install” button next to the SimpleSearch we downloaded

    Click "Continue" and then "OK"

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

    Title: Search results, check the “Do not show in menu” checkbox. Click on the “Settings” tab and uncheck the “Searchable” and “Use HTML editor” checkboxes. Don't forget to save the resource.

    8. Next, go to the newly created resource and enter [[!SimpleSearch]] in the “Resource Contents” field 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 page for displaying search results, 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:

    [[%sisea.search? &namespace=`sisea` &topic=`default`]]

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

    11. Next we solve problems with encoding

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

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

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

    12. Then replace the string $string = preg_replace("/" . $quoteValue . "/i", "$0", $string);

    $string = preg_replace("/" . $quoteValue . "/iu", "$0", $string);

    13. We also replace the line $text = preg_replace("/(\[\[\+.*?\]\])/i", "", $text);

    $text = preg_replace("/(\[\[\+.*?\]\])/iu", "", $text);

    14. And lastly, you need to comment out the line if (!empty($str)) $this->searchString = strip_tags($this->modx->sanitizeString($str)); Basic SimpleSearch chunks

    Search on the site running 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 .tpl format are located in 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 area. Here are their parameters

    • containerTpl
    • pageTpl
    • currentPageTpl

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

    tpl parameter - SimpleSearchResult chunk

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

    [[+idx]].