SimpleSearch stopped working after 1.10.2->1.13.0 update


#1

Running Grav 1.3.2
After update no results page is shown, only URL changes:
With 10.0.2 URL = /search/query:bla Content is list of results
With 1.13.0: URL = /?searchfield=bla Content is unchanged

/search/ is accessible and manual search via URL editing works.

Rendered HTMl for searchbox:

<div class="searchbox"> <div class="search-wrapper"> <form name="search" data-simplesearch-form> <input name="searchfield" class="search-input" type="text" min="3" required placeholder="Search..." value="" data-search-invalid="Please add at least 3 characters" data-search-separator=":" data-search-input="/grav/search/query" /> <button type="submit" class="search-submit"> <img src="/grav/user/plugins/simplesearch/assets/search.svg" /> </button> </form> </div> </div>


Not so SimpleSearch! Search box problem bypassed
#2

shouldn’t it be:

/search?query=bla

#3

Yes. I can test that by editing the URL.

The searchbox code (user/plugins/simplesearch/templates/partials/simplesearchbox.html.twig) changed.

(Sorry the forum software does not let me post the code).

Is “data-search-input” used at all in the new version?


#4

Could it be that simplesearch.js is not loaded?


#5

Do you have a custom override for anything? Simplesearch is working fine for me in my testing environment. However, I think that during this time we moved to a pure-JS implementation.


#6

I had the same problem. The simplesearch JavaScript was not added.

I did it in the theme at the bottom of the base.html.twig file with this line as a workaround :
<script type='text/javascript' src='{{ url('plugin://simplesearch/js/simplesearch.js') }}'></script>


#7

I used: {% do assets.addJs('plugin://simplesearch/js/simplesearch.js') %}
Your proposal has the same effect: I can see the script in the source and clicking the path shows the JS source.
Still, search does not work.

Andy, I have a simplified simplesearch_item.html.twig. Otherwise the plugin pages are unchanged.
I use my own theme derived from Learn2.


#8

So, you still get this URL : ‘/?searchfield=bla’ when searching ?


#9

Yes. URL is unchanged.


#10

Did you paste the JavaScript tag in the header or in the footer ?

If i paste it in the header it does not work for me either.


#11

You are correct. It works if I put your code snippet at the end just before /body


#12

Good to hear that it works. :grinning:


#13

I have the same issue with the “Prime” theme which have some changes and renards workaraund (thank you!) helped me to fix it.


#14

I’m confused. I have tried to check how SimpleSearch plugin work in the last demo of Pinpress Skeleton and it works good, but with ?searchfield=something, not with /search?query=something. In my case - if i use SimpleSearch plugin as is - it don’t work and url ends with ?searchfield=something. But if i use workaround from above - it works good but with /search.


#15

Hi @underr,

I had a short look at the Pinpress Skeleton. As far as I can see the search does not work in this theme because of the missing JavaScript.

I digged a bit deeper into this and found out that this line before the closing body tag of the base.html.twig file should add the JavaScript tag : {{ assets.js('bottom') }}
So, the workaround is not needed anymore.

This is already described here : https://learn.getgrav.org/themes/asset-manager .


#16

I also stumbled across the ?searchfield=something vs. ?query:something issue. GRAV version is 1.3.2, simplesearch version is 1.13.0 and I am using own templates based on grav-skeleton-blog-site 1.3.1. If I use the search template from simplesearch, it generates the ?query:something URL:

data-search-input="{{ base_url }}{{ config.plugins.simplesearch.route == '@self' ? '' : (config.plugins.simplesearch.route == '/' ? '' : config.plugins.simplesearch.route) }}/query"

But it still didn’t work with my browser (Chrome 38.0.2125.122). Yes it’s an old browser, so YMMV, but I want downward compatibility of my website.

I had to change the Javascript included by the simplesearch plugin from:

var fields = document.querySelectorAll('input[name="searchfield"][data-search-input]');
fields.forEach(function(field) {

into:

[].forEach.call(
    document.querySelectorAll('input[name="searchfield"]'), function(field) {

to make it work (forEach loops over arrays, but not DOM objects in older browsers).

In order to be able to substitute the Javascript for simplesearch’s built-in, I needed to modify simplesearch.php to not use its built-in JS, so I suppress it if built-in CSS is disabled (yes, I know that I shouldn’t modify standard files, but I found no other way to avoid editing the built-in Javascript and I already spent hours tracking down this bug or at least incompatibility with my Chrome version):

I changed simplesearch/simplesearch.php, line 294 from:

 if ($this->config->get('plugins.simplesearch.built_in_css')) {
    $this->grav['assets']->add('plugin://simplesearch/css/simplesearch.css');
}

$this->grav['assets']->addJs('plugin://simplesearch/js/simplesearch.js', [ 'group' => 'bottom' ]);

into:

if ($this->config->get('plugins.simplesearch.built_in_css')) {
    $this->grav['assets']->add('plugin://simplesearch/css/simplesearch.css');
    $this->grav['assets']->addJs('plugin://simplesearch/js/simplesearch.js', [ 'group' => 'bottom' ]);
}

and did include my own JS with the Asset Manager.

No it works with the results being filtered on the blog listing page and also with a separate result page using the ?query:something syntax used in simplesearch templates.


#17

So I should add:
{% block bottom %}
{{ assets.js(‘bottom’) }}
{% endblock %}
to my base.html.twig?


#18

Hi @stewag,

if you want to override or change your JavaScript somewhere in your theme use the code you mentioned above.
Otherwise the {{ assets.js(‘bottom’) }} should be enough.


#19

We have the same problem. There is bug somewhere. I will investigate and start a new topic.


#20

I had this same thing happen to me using the Twentyfifteen theme. As soon as I created a fresh theme, it worked fine.