Skip to content

Commit

Permalink
Merge branch 'release/1.14.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 8, 2018
2 parents 1ab46e7 + 7a01332 commit efc04ed
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 82 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# v1.14.2
## 12/07/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

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 2 additions & 4 deletions css/simplesearch.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@
}

.search-row:last-child hr {
display: none;
}


display: none;
}
7 changes: 5 additions & 2 deletions js/simplesearch.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -26,4 +29,4 @@
}
});
});
})());
})());
20 changes: 19 additions & 1 deletion languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ zh:
nl:
PLUGIN_SIMPLESEARCH:
SEARCH_PLACEHOLDER: "Zoeken …"
SEARCH_RESULTS: "Zoek resultaat"
SEARCH_RESULTS: "Zoek resultaten"
SEARCH_RESULTS_SUMMARY_SINGULAR: "Query: <strong>%s</strong> is 1 keer gevonden"
SEARCH_RESULTS_SUMMARY_PLURAL: "Query: <strong>%s</strong> is %s keer gevonden"
SEARCH_FIELD_MINIMUM_CHARACTERS: "Geef minstens %s tekens in"
hr:
PLUGIN_SIMPLESEARCH:
SEARCH_PLACEHOLDER: "Traži …"
Expand Down Expand Up @@ -107,3 +108,20 @@ da:
SEARCH_RESULTS: "Søgeresultat"
SEARCH_RESULTS_SUMMARY_SINGULAR: "Søgning: <strong>%s</strong> fandt et resultat"
SEARCH_RESULTS_SUMMARY_PLURAL: "Søgning: <strong>%s</strong> fandt %s resultater"

kk:
PLUGIN_SIMPLESEARCH:
SEARCH_PLACEHOLDER: "іздеу …"
SEARCH_RESULTS: "Іздеу нәтижесі"
SEARCH_RESULTS_SUMMARY_SINGULAR: "Сұраныс бойынша: <strong>%s</strong> табылды 1"
SEARCH_RESULTS_SUMMARY_PLURAL: "Сұраныс бойынша: <strong>%s</strong> табылды %s"
SEARCH_FIELD_MINIMUM_CHARACTERS: "Кемінде %s таңба қосу"

pl:
PLUGIN_SIMPLESEARCH:
SEARCH_PLACEHOLDER: "Szukaj…"
SEARCH_RESULTS: "Wyniki wyszukiwania"
SEARCH_RESULTS_SUMMARY_SINGULAR: "Znaleziono jeden wynik dla frazy <strong>%s</strong>."
SEARCH_RESULTS_SUMMARY_PLURAL: "Znaleziono %2$s wyników dla frazy <strong>%1$s</strong>."
SEARCH_FIELD_MINIMUM_CHARACTERS: "Fraza musi składać się z minimum %s znaków."

96 changes: 49 additions & 47 deletions simplesearch.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

namespace Grav\Plugin;

use Grav\Common\Config\Config;
use Grav\Common\Data\Data;
use Grav\Common\Page\Collection;
use Grav\Common\Plugin;
use Grav\Common\Uri;
use Grav\Common\Page\Page;
use Grav\Common\Page\Types;
use Grav\Common\Plugin;
use Grav\Common\Taxonomy;
use Grav\Common\Uri;
use Grav\Common\Utils;
use Grav\Common\Data\Data;
use Grav\Common\Config\Config;
use RocketTheme\Toolbox\Event\Event;

class SimplesearchPlugin extends Plugin
Expand Down Expand Up @@ -117,7 +118,7 @@ public function onPagesInitialized()
$taxonomies = [];
$find_taxonomy = [];

$filters = (array) $this->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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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
Expand All @@ -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($taxonomies) && !empty($taxonomies) && !in_array($taxonomy, $taxonomies)) {
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;
Expand All @@ -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']);
}
}
}
2 changes: 1 addition & 1 deletion simplesearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ route: /search
search_content: rendered
template: simplesearch_results
filters:
category: blog
category:
filter_combinator: and
ignore_accented_characters: false
order:
Expand Down
8 changes: 4 additions & 4 deletions templates/partials/simplesearch_item.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{% set banner = page.media.images|first %}

{% if banner %}
<div class="search-image">
<a href="{{ page.url }}">{{ banner.cropZoom(100,100).html|raw }}</a>
</div>
<div class="search-image">
<a href="{{ page.url }}">{{ banner.cropZoom(100,100).html|raw }}</a>
</div>
{% endif %}
<div class="search-item">
<div class="search-title">
Expand All @@ -18,6 +18,6 @@

<p>{{ page.summary|raw }}</p>

<hr />
<hr/>
</div>
</section>
33 changes: 16 additions & 17 deletions templates/simplesearch_results.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

{% block content %}
<div class="content-padding simplesearch">
<h1 class="search-header">{{"PLUGIN_SIMPLESEARCH.SEARCH_RESULTS"|t}}</h1>
<div class="center">
{% include 'partials/simplesearch_searchbox.html.twig' %}
</div>

<p>
{% 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 }}
<h1 class="search-header">{{ "PLUGIN_SIMPLESEARCH.SEARCH_RESULTS"|t }}</h1>
<div class="center">
{% include 'partials/simplesearch_searchbox.html.twig' %}
</div>
<p>
{% 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 %}
</p>
{% for page in search_results %}
{% include 'partials/simplesearch_item.html.twig' with {'page':page} %}
{% endfor %}
</p>
{% for page in search_results %}
{% include 'partials/simplesearch_item.html.twig' with {'page': page} %}
{% endfor %}
</div>
{% endblock %}

0 comments on commit efc04ed

Please sign in to comment.