# Grav SimpleSearch Plugin ![SimpleSearch](assets/readme_1.png) `SimpleSearch` is a simple, yet very powerful [Grav][grav] plugin that adds search capabilities to your Grav instance. By default it can search Page **Titles**, **Content**, **Taxonomy**, and also a raw page **Header**. # Installation Installing the SimpleSearch plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file. ## GPM Installation (Preferred) The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line). From the root of your Grav install type: bin/gpm install simplesearch This will install the SimpleSearch plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/simplesearch`. ## Manual Installation To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `simplesearch`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-simplesearch) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras). You should now have all the plugin files under /your/site/grav/user/plugins/simplesearch > NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav), the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) plugins, and a theme to be installed in order to operate. # Config Options To effectively use the plugin, you first need to create an override config. To do so, create the folder `user/config/plugins` (if it doesn't exist already) and copy the [simplesearch.yaml][simplesearch] config file in there. ``` enabled: true built_in_css: true built_in_js: true display_button: false min_query_length: 3 route: /search search_content: rendered template: simplesearch_results filters: category: filter_combinator: and ignore_accented_characters: false order: by: date dir: desc searchable_types: title: true content: true taxonomy: true header: false header_keys_ignored: ['title', 'taxonomy','content', 'form', 'forms', 'media_order'] ``` By creating the configuration file: `user/config/plugins/simplesearch.yaml` you have effectively created a site-wide configuration for SimpleSearch. However, you may want to have multiple searches. > NOTE: If you want to search **ALL PAGES** just keep the `filters` section empty. To accomplish multiple search types in a single site, you should use **page-based** configuration. This is simple to do, simply provide any or all of the configuration options under a `simplesearch:` header in your page frontmatter. For example: ``` simplesearch: process: true route: @self filters: - @self - @taxonomy: [tag] filter_combinator: and ``` These page headers will only be taken into account if the search route points to this page. For example: here the route points to `@self` which in turn resolves to `/blog`. You can also specify the route explicitly with `route: /blog` if you so choose. This header is within the `/user/pages/blog/blog.md` file. We will cover this self-controlled form of search handling below. # Usage There are two approaches to using SimpleSearch. ## 1. Standalone Search Page This is the traditional approach and involves having a searchbox 'somewhere' on your site. When you search you are shown a new page that displays the search results. On this page you will see a summary of the results and be able to click a link to visit each applicable page within your site. Think about how **Google** and other traditional search engines work. After installing the SimpleSearch plugin, you can add a simple **searchbox** to your site by including the provided twig template. Or copy it from the plugin to your theme and customize it as you please: ``` {% include 'partials/simplesearch_searchbox.html.twig' %} ``` By default the **simplesearch_searchbox** Twig template uses the `route` as defined in the configuration. The SimpleSearch plugin uses this route and then appends a `query:` parameter to create the following final URL. ``` http://yoursite.com/search/query:something ``` 1. `/search`: This is the **route** setting and it can be changed 2. `/query:something`: This is the query itself, where `something` is what you are searching for. The plugin actively looks for URLs requested that match the configured `route` and if so it intercepts the call and renders the results template as specified by the configuration options, (defaults to `simplesearch_results.html.twig` as provided by the plugin). With this approach, the filters control which pages are searched. You can have multiple taxonomy filters here, and can configure the combinator to require **any** match (via `or`) or require **all** conditions to match (via `and`). You can also completely customize the look and feel of the results by overriding the template. There are two methods to do this. 1. Copy the file [templates/simplesearch_results.html.twig][results] under your theme templates `user/themes/_your-theme_/templates/` and customize it. 2. Create your very own results output. For this you need to change the `template` reference in the config (let's say **mysearch_results**). In your theme you would then create the new template under `user/themes/_your-theme_/templates/mysearch_results.html.twig` and write your customizations. This is how it looks by default: ``` {% extends 'partials/simplesearch_base.html.twig' %} {% block content %}