diff --git a/CHANGELOG.md b/CHANGELOG.md index 11f9cc8..7ff65d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# v2.2.0 +## 09/14/2020 + +1. [](#improved) + * Added config option to choose keys to ignore when searching header + * Added ability to opt-out of page search by setting: `simplesearch: process: false` in page header + * Added `form` and `forms` to default list of ignores in page header searches +1. [](#bugfix) + * Fix issue to ensure matching ignore keys only checked at root level + * Fix issue where searchable header content was growing exponentially + # v2.1.0 ## 05/27/2020 diff --git a/README.md b/README.md index adeb6aa..f8d7d0a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ searchable_types: 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. @@ -61,6 +62,7 @@ To accomplish multiple search types in a single site, you should use **page-base ``` simplesearch: + process: true route: @self filters: - @self @@ -169,6 +171,15 @@ filters: - '@taxonomy': false ``` +## Ignoring a page + +A page can be setup to "opt-out" of being included in the search results by setting the following in page frontmatter: + +```yaml +simplesearch: + process: false +``` + ## Ignoring accented characters You can tell Simplesearch to return a positive value when searching for characters that have an accent. So `éè` for example will be both equivalent to `e`. diff --git a/blueprints.yaml b/blueprints.yaml index f53b706..a3d016a 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: SimpleSearch -version: 2.1.0 +version: 2.2.0 description: "Don't be fooled, the **SimpleSearch** plugin provides a **fast** and highly **configurable** way to search your content." icon: search author: @@ -111,6 +111,15 @@ form: taxonomy: Taxonomy use: keys + header_keys_ignored: + type: selectize + size: large + label: PLUGIN_SIMPLESEARCH.HEADER_KEYS_IGNORED + help: PLUGIN_SIMPLESEARCH.HEADER_KEYS_IGNORED_HELP + classes: fancy + validate: + type: commalist + template: type: text size: medium @@ -136,23 +145,23 @@ form: or: PLUGIN_SIMPLESEARCH.OR_COMBINATOR order.by: - type: select - size: long - classes: fancy - label: PLUGIN_ADMIN.DEFAULT_ORDERING - help: PLUGIN_ADMIN.DEFAULT_ORDERING_HELP - options: - default: PLUGIN_ADMIN.DEFAULT_ORDERING_DEFAULT - folder: PLUGIN_ADMIN.DEFAULT_ORDERING_FOLDER - title: PLUGIN_ADMIN.DEFAULT_ORDERING_TITLE - date: PLUGIN_ADMIN.DEFAULT_ORDERING_DATE + type: select + size: long + classes: fancy + label: PLUGIN_ADMIN.DEFAULT_ORDERING + help: PLUGIN_ADMIN.DEFAULT_ORDERING_HELP + options: + default: PLUGIN_ADMIN.DEFAULT_ORDERING_DEFAULT + folder: PLUGIN_ADMIN.DEFAULT_ORDERING_FOLDER + title: PLUGIN_ADMIN.DEFAULT_ORDERING_TITLE + date: PLUGIN_ADMIN.DEFAULT_ORDERING_DATE order.dir: - type: toggle - label: PLUGIN_ADMIN.DEFAULT_ORDER_DIRECTION - highlight: asc - default: desc - help: PLUGIN_ADMIN.DEFAULT_ORDER_DIRECTION_HELP - options: - asc: PLUGIN_ADMIN.ASCENDING - desc: PLUGIN_ADMIN.DESCENDING + type: toggle + label: PLUGIN_ADMIN.DEFAULT_ORDER_DIRECTION + highlight: asc + default: desc + help: PLUGIN_ADMIN.DEFAULT_ORDER_DIRECTION_HELP + options: + asc: PLUGIN_ADMIN.ASCENDING + desc: PLUGIN_ADMIN.DESCENDING diff --git a/languages.yaml b/languages.yaml index 00ce869..1ba12a4 100644 --- a/languages.yaml +++ b/languages.yaml @@ -28,7 +28,9 @@ en: AND_COMBINATOR: 'And - Boolean &&' OR_COMBINATOR: 'Or - Boolean ||' SEARCHABLE_TYPES: "Searchable Types" - SEARCHABLE_TYPES_DESCRIPTION: "Title = Search Page Title
Content = Search Page Content
Header = Search Raw Headers (excluding title, content, taxonomy)
Taxonomy = Search Taxonomy" + SEARCHABLE_TYPES_DESCRIPTION: "Title = Search Page Title
Content = Search Page Content
Header = Search Raw Page Headers
Taxonomy = Search Taxonomy" + HEADER_KEYS_IGNORED: Header Keys to Ignore + HEADER_KEYS_IGNORED_HELP: The root-level header keys that should be skipped when searching type "Header" ro: PLUGIN_SIMPLESEARCH: @@ -53,7 +55,7 @@ fr: SEARCH_RESULTS_SUMMARY_SINGULAR: "Recherche : Un résultat trouvé pour %s" SEARCH_RESULTS_SUMMARY_PLURAL: "Recherche : %2$s résultats trouvés pour %1$s" SEARCH_FIELD_MINIMUM_CHARACTERS: "Veuillez ajouter au moins %s caractères" - + it: PLUGIN_SIMPLESEARCH: SEARCH_PLACEHOLDER: "Cerca …" @@ -150,7 +152,7 @@ uk: FILTER_COMBINATOR: 'Фільтр комбінатор' AND_COMBINATOR: 'І - Булева &&' OR_COMBINATOR: 'Або - Булева ||' - + es: PLUGIN_SIMPLESEARCH: SEARCH_PLACEHOLDER: "Buscar …" diff --git a/simplesearch.php b/simplesearch.php index df7a43f..eebd358 100644 --- a/simplesearch.php +++ b/simplesearch.php @@ -201,6 +201,13 @@ public function onPagesInitialized() if ($query) { foreach ($this->collection as $cpage) { + + $header = $cpage->header(); + if (isset($header->simplesearch['process']) && $header->simplesearch['process'] === false) { + $this->collection->remove($cpage); + continue; + } + foreach ($this->query as $query) { $query = trim($query); @@ -393,15 +400,24 @@ public function onTwigSiteVariables() } } - protected function getArrayValues($array, $ignore_keys = ['title','taxonomy','content'], $output = '') { + protected function getArrayValues($array, $ignore_keys = null, $level = 0) { + $output = ''; + + if (is_null($ignore_keys)) { + $ignore_keys = $this->config()->header_keys_ignored; + } foreach ($array as $key => $child) { - if (!in_array($key, $ignore_keys)) { - if (is_array($child)) { - $output .= " " . $this->getArrayValues($child, $ignore_keys, $output); - } else { - $output .= " " . $child; - } + + if ($level === 0 && in_array($key, $ignore_keys)) { + continue; + } + + if (is_array($child)) { + $output .= " " . $this->getArrayValues($child, $ignore_keys, $level + 1); + } else { + $output .= " " . $child; } + } return trim($output); } diff --git a/simplesearch.yaml b/simplesearch.yaml index b50ac27..3a234ce 100644 --- a/simplesearch.yaml +++ b/simplesearch.yaml @@ -7,14 +7,15 @@ route: /search search_content: rendered template: simplesearch_results filters: - category: + category: filter_combinator: and ignore_accented_characters: false order: - by: date - dir: desc + by: date + dir: desc searchable_types: - title: true - content: true - taxonomy: true - header: false \ No newline at end of file + title: true + content: true + taxonomy: true + header: false +header_keys_ignored: [ 'title', 'taxonomy','content', 'form', 'forms', 'media_order' ] \ No newline at end of file