From 1e381a79912987693fca3f551a18d3a0f7b229f6 Mon Sep 17 00:00:00 2001 From: Willem Oosting Date: Mon, 21 May 2018 07:10:00 +0200 Subject: [PATCH 01/11] Search form field passed variable name fix. (#156) The `name` of a form field's input is also the variable-name that is passed. Apparently the search plugin expects a variable named: "query" to be passed, not a "searchfield"-named variable. Performing a manual search from the dedicated page does not present any results without this change. --- templates/partials/simplesearch_searchbox.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/partials/simplesearch_searchbox.html.twig b/templates/partials/simplesearch_searchbox.html.twig index c0fbd39..0ded504 100644 --- a/templates/partials/simplesearch_searchbox.html.twig +++ b/templates/partials/simplesearch_searchbox.html.twig @@ -2,7 +2,7 @@
0 %} min="{{- min_chars -}}" {% endif %} From 9ddcdd8dcc36c596ce936886bf0aadf0a6d46c4d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 20 Jul 2018 16:45:54 -0600 Subject: [PATCH 02/11] Revert "Search form field passed variable name fix. (#156)" This reverts commit 1e381a79912987693fca3f551a18d3a0f7b229f6. --- templates/partials/simplesearch_searchbox.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/partials/simplesearch_searchbox.html.twig b/templates/partials/simplesearch_searchbox.html.twig index 0ded504..c0fbd39 100644 --- a/templates/partials/simplesearch_searchbox.html.twig +++ b/templates/partials/simplesearch_searchbox.html.twig @@ -2,7 +2,7 @@
0 %} min="{{- min_chars -}}" {% endif %} From 26a1ebf3bae6f2d683288a304812bcbf52163169 Mon Sep 17 00:00:00 2001 From: Chris Wilcox Date: Sat, 21 Jul 2018 08:48:23 +1000 Subject: [PATCH 03/11] Updated javascript to be compatible with IE11. (#161) --- js/simplesearch.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/simplesearch.js b/js/simplesearch.js index e76c1cc..8664009 100644 --- a/js/simplesearch.js +++ b/js/simplesearch.js @@ -1,11 +1,14 @@ ((function(){ + if (!Element.prototype.matches) { + Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; + } var findAncestor = function(el, selector) { while ((el = el.parentElement) && !((el.matches || el.matchesSelector).call(el, selector))) {} return el; }; var fields = document.querySelectorAll('input[name="searchfield"][data-search-input]'); - fields.forEach(function(field) { + Array.prototype.forEach.call(fields, function(field) { var form = findAncestor(field, 'form[data-simplesearch-form]'), min = field.getAttribute('min') || false, location = field.getAttribute('data-search-input'), @@ -26,4 +29,4 @@ } }); }); -})()); \ No newline at end of file +})()); From f2f596ebe068f50d198f5e8e27390b204208efee Mon Sep 17 00:00:00 2001 From: Marcin Ochyra Date: Sat, 21 Jul 2018 00:53:53 +0200 Subject: [PATCH 04/11] Polish translation (#144) --- languages.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/languages.yaml b/languages.yaml index c703125..9805896 100644 --- a/languages.yaml +++ b/languages.yaml @@ -107,3 +107,10 @@ da: SEARCH_RESULTS: "Søgeresultat" SEARCH_RESULTS_SUMMARY_SINGULAR: "Søgning: %s fandt et resultat" SEARCH_RESULTS_SUMMARY_PLURAL: "Søgning: %s fandt %s resultater" +pl: + PLUGIN_SIMPLESEARCH: + SEARCH_PLACEHOLDER: "Szukaj…" + SEARCH_RESULTS: "Wyniki wyszukiwania" + SEARCH_RESULTS_SUMMARY_SINGULAR: "Znaleziono jeden wynik dla frazy %s." + SEARCH_RESULTS_SUMMARY_PLURAL: "Znaleziono %2$s wyników dla frazy %1$s." + SEARCH_FIELD_MINIMUM_CHARACTERS: "Fraza musi składać się z minimum %s znaków." From a03a47d5657cc0aef8075cc34ede61875e5235be Mon Sep 17 00:00:00 2001 From: Robbert Date: Sat, 21 Jul 2018 00:54:11 +0200 Subject: [PATCH 05/11] Spelling corrections (#145) Few corrections --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8fea46c..562a797 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ simplesearch: filter_combinator: and ``` - These page headers will only be taken into account if the search route points to this page. For example: here the the route points to `@self` which in turn resolves to `/blog`. You can also specify the route explicity 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. + 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 @@ -79,7 +79,7 @@ After installing the SimpleSearch plugin, you can add a simple **searchbox** to {% 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:` paramater to create the following final URL. +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 @@ -115,9 +115,9 @@ You can also completely customize the look and feel of the results by overriding ## 2. Self-Controlled Search Page -This is a new feature of SimpleSearch and it very useful and simple way to provide a 'filter' like search of a collection listing page. In this example, we will assume you have a Blog listing page you wish to be able to search and filter based on a search box. +This is a new feature of SimpleSearch and it's a very useful and simple way to provide a 'filter' like search of a collection listing page. In this example, we will assume you have a Blog listing page you wish to be able to search and filter based on a search box. -To accomplish this, you need ot use the page-based configuration as described above, and configure multiple filters, `@self` to use the page's content collection: http://learn.getgrav.org/content/headers#collection-headers +To accomplish this, you need to use the page-based configuration as described above, and configure multiple filters, `@self` to use the page's content collection: http://learn.getgrav.org/content/headers#collection-headers ``` content: @@ -137,7 +137,7 @@ The only thing needed to provide this functionality is a search box that points ## Performance -Simple search is not a full-fledged index-powered search engine. It merely iterates over the pages and searches the content and title for matching strings. That's it. This is not going to result in screaming fast searches if your site has lots of content. One way to optimize things a little is to change the `search_content` configuration option from `rendered` to `raw`. This means the `rawMarkdown()` method is used rather than the `content()` method, to retrieve the page content, and in turn means plugin events, markdown processing, image processing, and other time consuming tasks are not performed. This can often yield adequate search results without the need for all this extra work. +Simplesearch is not a full-fledged index-powered search engine. It merely iterates over the pages and searches the content and title for matching strings. That's it. This is not going to result in screaming fast searches if your site has lots of content. One way to optimize things a little is to change the `search_content` configuration option from `rendered` to `raw`. This means the `rawMarkdown()` method is used rather than the `content()` method, to retrieve the page content, and in turn means plugin events, markdown processing, image processing, and other time-consuming tasks are not performed. This can often yield adequate search results without the need for all this extra work. ## Searching Taxonomy From 8a42f06e2bbdade2c2238353715c04a428966565 Mon Sep 17 00:00:00 2001 From: Vincent Purcell Date: Fri, 20 Jul 2018 18:55:12 -0400 Subject: [PATCH 06/11] Issue #131 ensure $values is an array to prevent PHP error on implode() (#146) Some plugins (such as Events) add taxonomy values that do not resolve in arrays as the simplesearch expects, so skip them. --- simplesearch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesearch.php b/simplesearch.php index 2be5302..582ae00 100644 --- a/simplesearch.php +++ b/simplesearch.php @@ -339,7 +339,7 @@ private function notFound($query, $page, $taxonomies) $taxonomy_match = false; foreach ((array) $page_taxonomies as $taxonomy => $values) { // if taxonomies filter set, make sure taxonomy filter is valid - if (is_array($taxonomies) && !empty($taxonomies) && !in_array($taxonomy, $taxonomies)) { + if (!is_array($values) || (is_array($taxonomies) && !empty($taxonomies) && !in_array($taxonomy, $taxonomies))) { continue; } From 8d6a8d2f444c87c3de9092d075cf13f4954dd4a0 Mon Sep 17 00:00:00 2001 From: Alexander Kim Date: Sat, 21 Jul 2018 04:56:55 +0600 Subject: [PATCH 07/11] Added Kazakh translations (#153) Kazakh translations (kk) --- languages.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/languages.yaml b/languages.yaml index 9805896..d80a34d 100644 --- a/languages.yaml +++ b/languages.yaml @@ -107,6 +107,15 @@ da: SEARCH_RESULTS: "Søgeresultat" SEARCH_RESULTS_SUMMARY_SINGULAR: "Søgning: %s fandt et resultat" SEARCH_RESULTS_SUMMARY_PLURAL: "Søgning: %s fandt %s resultater" + +kk: + PLUGIN_SIMPLESEARCH: + SEARCH_PLACEHOLDER: "іздеу …" + SEARCH_RESULTS: "Іздеу нәтижесі" + SEARCH_RESULTS_SUMMARY_SINGULAR: "Сұраныс бойынша: %s табылды 1" + SEARCH_RESULTS_SUMMARY_PLURAL: "Сұраныс бойынша: %s табылды %s" + SEARCH_FIELD_MINIMUM_CHARACTERS: "Кемінде %s таңба қосу" + pl: PLUGIN_SIMPLESEARCH: SEARCH_PLACEHOLDER: "Szukaj…" @@ -114,3 +123,4 @@ pl: SEARCH_RESULTS_SUMMARY_SINGULAR: "Znaleziono jeden wynik dla frazy %s." SEARCH_RESULTS_SUMMARY_PLURAL: "Znaleziono %2$s wyników dla frazy %1$s." SEARCH_FIELD_MINIMUM_CHARACTERS: "Fraza musi składać się z minimum %s znaków." + From feea59768a94b8dcc1f5a3fd1d843257faec3ca2 Mon Sep 17 00:00:00 2001 From: Robbert Date: Sat, 21 Jul 2018 01:39:58 +0200 Subject: [PATCH 08/11] optimize + cleanup + rm typos (#163) * optimize + cleanup + rm typos * Update simplesearch_results.html.twig Replace `==` with `is same as` (`===`) --- css/simplesearch.css | 6 +- languages.yaml | 3 +- simplesearch.php | 94 ++++++++++--------- .../partials/simplesearch_item.html.twig | 8 +- templates/simplesearch_results.html.twig | 33 ++++--- 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/css/simplesearch.css b/css/simplesearch.css index 0423146..3d0eba7 100644 --- a/css/simplesearch.css +++ b/css/simplesearch.css @@ -38,7 +38,5 @@ } .search-row:last-child hr { - display: none; -} - - + display: none; +} \ No newline at end of file diff --git a/languages.yaml b/languages.yaml index d80a34d..959a101 100644 --- a/languages.yaml +++ b/languages.yaml @@ -45,9 +45,10 @@ zh: nl: PLUGIN_SIMPLESEARCH: SEARCH_PLACEHOLDER: "Zoeken …" - SEARCH_RESULTS: "Zoek resultaat" + SEARCH_RESULTS: "Zoek resultaten" SEARCH_RESULTS_SUMMARY_SINGULAR: "Query: %s is 1 keer gevonden" SEARCH_RESULTS_SUMMARY_PLURAL: "Query: %s is %s keer gevonden" + SEARCH_FIELD_MINIMUM_CHARACTERS: "Geef minstens %s tekens in" hr: PLUGIN_SIMPLESEARCH: SEARCH_PLACEHOLDER: "Traži …" diff --git a/simplesearch.php b/simplesearch.php index 582ae00..ada55cd 100644 --- a/simplesearch.php +++ b/simplesearch.php @@ -1,15 +1,16 @@ config->get('plugins.simplesearch.filters'); + $filters = (array)$this->config->get('plugins.simplesearch.filters'); $operator = $this->config->get('plugins.simplesearch.filter_combinator', 'and'); $new_approach = false; @@ -154,7 +155,7 @@ public function onPagesInitialized() if ($key === '@self' || $key === 'self@') { $new_approach = true; } elseif ($key === '@taxonomy' || $key === 'taxonomy@') { - $taxonomies = $filter === false ? false : array_merge($taxonomies, (array) $filter); + $taxonomies = $filter === false ? false : array_merge($taxonomies, (array)$filter); } else { $find_taxonomy[$key] = $filter; } @@ -174,7 +175,7 @@ public function onPagesInitialized() $this->collection->published()->routable(); //Check if user has permission to view page - if($this->grav['config']->get('plugins.login.enabled')) { + if ($this->grav['config']->get('plugins.login.enabled')) { $this->collection = $this->checkForPermissions($this->collection); } $extras = []; @@ -280,42 +281,6 @@ public function checkForPermissions($collection) return $returnCollection; } - /** - * Set needed variables to display the search results. - */ - public function onTwigSiteVariables() - { - $twig = $this->grav['twig']; - - if ($this->query) { - $twig->twig_vars['query'] = implode(', ', $this->query); - $twig->twig_vars['search_results'] = $this->collection; - } - - if ($this->config->get('plugins.simplesearch.built_in_css')) { - $this->grav['assets']->add('plugin://simplesearch/css/simplesearch.css'); - } - - if ($this->config->get('plugins.simplesearch.built_in_js')) { - $this->grav['assets']->addJs('plugin://simplesearch/js/simplesearch.js', [ 'group' => 'bottom' ]); - } - } - - private function matchText($haystack, $needle) { - if ($this->config->get('plugins.simplesearch.ignore_accented_characters')) { - setlocale(LC_ALL, 'en_US'); - try { - $result = mb_stripos(iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $haystack), iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $needle)); - } catch (\Exception $e) { - $result = mb_stripos($haystack, $needle); - } - setlocale(LC_ALL, ''); - return $result; - } else { - return mb_stripos($haystack, $needle); - } - } - /** * @param $query * @param Page $page @@ -337,13 +302,13 @@ private function notFound($query, $page, $taxonomies) } $page_taxonomies = $page->taxonomy(); $taxonomy_match = false; - foreach ((array) $page_taxonomies as $taxonomy => $values) { + foreach ((array)$page_taxonomies as $taxonomy => $values) { // if taxonomies filter set, make sure taxonomy filter is valid if (!is_array($values) || (is_array($taxonomies) && !empty($taxonomies) && !in_array($taxonomy, $taxonomies))) { continue; } - $taxonomy_values = implode('|',$values); + $taxonomy_values = implode('|', $values); if ($this->matchText($taxonomy_values, $query) !== false) { $taxonomy_match = true; break; @@ -359,10 +324,47 @@ private function notFound($query, $page, $taxonomies) $result = $this->matchText(strip_tags($content), $query) === false; } $results = $results && $result; - if ($results === false ) { + if ($results === false) { break; } } return $results; } + + private function matchText($haystack, $needle) + { + if ($this->config->get('plugins.simplesearch.ignore_accented_characters')) { + setlocale(LC_ALL, 'en_US'); + try { + $result = mb_stripos(iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $haystack), iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $needle)); + } catch (\Exception $e) { + $result = mb_stripos($haystack, $needle); + } + setlocale(LC_ALL, ''); + return $result; + } else { + return mb_stripos($haystack, $needle); + } + } + + /** + * Set needed variables to display the search results. + */ + public function onTwigSiteVariables() + { + $twig = $this->grav['twig']; + + if ($this->query) { + $twig->twig_vars['query'] = implode(', ', $this->query); + $twig->twig_vars['search_results'] = $this->collection; + } + + if ($this->config->get('plugins.simplesearch.built_in_css')) { + $this->grav['assets']->add('plugin://simplesearch/css/simplesearch.css'); + } + + if ($this->config->get('plugins.simplesearch.built_in_js')) { + $this->grav['assets']->addJs('plugin://simplesearch/js/simplesearch.js', ['group' => 'bottom']); + } + } } diff --git a/templates/partials/simplesearch_item.html.twig b/templates/partials/simplesearch_item.html.twig index 2fde834..feab4a6 100644 --- a/templates/partials/simplesearch_item.html.twig +++ b/templates/partials/simplesearch_item.html.twig @@ -3,9 +3,9 @@ {% set banner = page.media.images|first %} {% if banner %} - + {% endif %}
@@ -18,6 +18,6 @@

{{ page.summary|raw }}

-
+
diff --git a/templates/simplesearch_results.html.twig b/templates/simplesearch_results.html.twig index 68f5976..539a1d7 100644 --- a/templates/simplesearch_results.html.twig +++ b/templates/simplesearch_results.html.twig @@ -2,23 +2,22 @@ {% block content %}
-

{{"PLUGIN_SIMPLESEARCH.SEARCH_RESULTS"|t}}

-
- {% include 'partials/simplesearch_searchbox.html.twig' %} -
- -

- {% if query %} - {% set count = search_results ? search_results.count : 0 %} - {% if count == 1 %} - {{ "PLUGIN_SIMPLESEARCH.SEARCH_RESULTS_SUMMARY_SINGULAR"|t(query|e)|raw }} - {% else %} - {{ "PLUGIN_SIMPLESEARCH.SEARCH_RESULTS_SUMMARY_PLURAL"|t(query|e, count)|raw }} +

{{ "PLUGIN_SIMPLESEARCH.SEARCH_RESULTS"|t }}

+
+ {% include 'partials/simplesearch_searchbox.html.twig' %} +
+

+ {% if query %} + {% set count = search_results ? search_results.count : 0 %} + {% if count is same as( 1 ) %} + {{ "PLUGIN_SIMPLESEARCH.SEARCH_RESULTS_SUMMARY_SINGULAR"|t(query|e)|raw }} + {% else %} + {{ "PLUGIN_SIMPLESEARCH.SEARCH_RESULTS_SUMMARY_PLURAL"|t(query|e, count)|raw }} + {% endif %} {% endif %} - {% endif %} -

- {% for page in search_results %} - {% include 'partials/simplesearch_item.html.twig' with {'page':page} %} - {% endfor %} +

+ {% for page in search_results %} + {% include 'partials/simplesearch_item.html.twig' with {'page': page} %} + {% endfor %}
{% endblock %} From b9ab30b109f9e7f3195c1d20c055d82000d37694 Mon Sep 17 00:00:00 2001 From: Grant Date: Fri, 7 Dec 2018 20:19:05 -0600 Subject: [PATCH 09/11] Prevent the default filter being blog (#166) When the category is removed when using the admin plugin, the user config falls back to using the default configuration for `filters`, which will be just an empty array when parsed. This will fix #158 and provide better default behavior. --- simplesearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplesearch.yaml b/simplesearch.yaml index e400ca3..794d3fc 100644 --- a/simplesearch.yaml +++ b/simplesearch.yaml @@ -7,7 +7,7 @@ route: /search search_content: rendered template: simplesearch_results filters: - category: blog + category: filter_combinator: and ignore_accented_characters: false order: From 2bfd3f6cee743bfcf343340c3915f21337cfa89b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 7 Dec 2018 19:26:16 -0700 Subject: [PATCH 10/11] updated changelog --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 136d9cc..4c0b5fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# v1.14.2 +## mm/dd/2018 + +1. [](#improved) + * Optimize, cleanup and remove typos [#163](https://github.com/getgrav/grav-plugin-simplesearch/pull/163) + * Removed `blog` as default filter [#166](https://github.com/getgrav/grav-plugin-simplesearch/pull/166) + * Polish translation [#144](https://github.com/getgrav/grav-plugin-simplesearch/pull/144) + * Kazakh translation [#153](https://github.com/getgrav/grav-plugin-simplesearch/pull/153) + * Spelling corrections [#145](https://github.com/getgrav/grav-plugin-simplesearch/pull/145) +1. [](#bugfix) + * Fix JS to work with IE11 [#161](https://github.com/getgrav/grav-plugin-simplesearch/pull/161) + * Updated javascript to be compatible with IE11 [#161](https://github.com/getgrav/grav-plugin-simplesearch/pull/161) + * Ensure `$values` is an array to prevent PHP error on implode [#146](https://github.com/getgrav/grav-plugin-simplesearch/pull/146) + # v1.14.1 ## 01/11/2018 From 7a01332f6fc7ff8096981c3a0c853dd02aed7fd6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 7 Dec 2018 19:29:10 -0700 Subject: [PATCH 11/11] Prepare for release --- CHANGELOG.md | 2 +- blueprints.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c0b5fc..70d5914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v1.14.2 -## mm/dd/2018 +## 12/07/2018 1. [](#improved) * Optimize, cleanup and remove typos [#163](https://github.com/getgrav/grav-plugin-simplesearch/pull/163) diff --git a/blueprints.yaml b/blueprints.yaml index 1f83610..2d9d54d 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: SimpleSearch -version: 1.14.1 +version: 1.14.2 description: "Don't be fooled, the **SimpleSearch** plugin provides a **fast** and highly **configurable** way to search your content." icon: search author: