How to change search url behavior?

When we search on the front end, like “Chocolate 70%”, the URL of the search goes like:
search?q=Chocolate%2070%
So, I get a 404 error, I belive that happens because shopify uses de % who fill the splits of the word.

@RaphaelZCO
thanks for posting here, can you please share your store link?

I think in your case, the search URL should be encoded as follows:
“search?q=Chocolate%2070%25”

By adding “%25” instead of “%”, you ensure that the “%” character is correctly interpreted in the URL and doesn’t cause any errors or conflicts.
If you find ways to resolve it, you can share them for us.

But how can I change de search behaivor? I just uses the search and discovery app. I did not find a way to modify this.

This is an error in your theme code.

If you type your search term and press Enter instead of clicking the button, the search should show results.

Unfortunately, I do not have a copy of your theme, so can’t point exactly how to fix this without looking at the theme code.

probably sections/helper-predictive-search.liquid

You’d need to look for code similar to:

...

Share the code here and then it’d be possible to suggest a fix.

Or, try reaching out to Krown themes (it’s Local, right?) – they’d want to fix it themselves.

I didn´t know that the theme could change the search behavior.

Here is the code, thank you so much

{%- if predictive_search.performed -%}

{%- if predictive_search.resources.queries.size > 0 or predictive_search.resources.collections.size > 0 -%}

{%- for query in predictive_search.resources.queries -%} {{ query.styled_text }} {%- endfor -%} {%- for collection in predictive_search.resources.collections -%} {{ collection.title }} {%- endfor -%}
{%- endif -%}

{%- if predictive_search.resources.products.size > 0 -%}

{{ ‘search.form.product_results_title’ | t }}

{%- for product in predictive_search.resources.products -%}

{%- render 'lazy-image-small', image: product.featured_media, aspect_ratio: settings.cart_image_ratio, fit: settings.cart_image_fit -%}

{%- liquid
if settings.show_currency_codes
assign iso_code = localization.country.currency.iso_code | prepend: ’ ’
endif
-%}

{%- assign variant = product.selected_or_first_available_variant -%} {{ 'general.accessibility_labels.price.regular' | t }} {{ variant.price | money | append: iso_code }} {%- if variant.compare_at_price > variant.price -%} {{ 'general.accessibility_labels.price.sale' | t }} {{ variant.compare_at_price | money | append: iso_code }} {%- endif -%} {%- if variant.unit_price_measurement -%} {{ variant.unit_price | money | append: iso_code }} / {% if variant.unit_price_measurement.reference_value != 1 %} {{ variant.unit_price_measurement.reference_value }} {% endif %} {{ variant.unit_price_measurement.reference_unit }} {%- endif -%}
{{ product.title | escape }}

{%- endfor -%}

{%- endif -%}

{%- if predictive_search.resources.pages.size > 0 -%}

{{ 'search.form.page_results_title' | t }} {%- for page in predictive_search.resources.pages -%} {{ page.title | escape }} {%- endfor -%}
{%- endif -%}

{%- if predictive_search.resources.articles.size > 0 -%}

{{ 'search.form.article_results_title' | t }} {%- for article in predictive_search.resources.articles -%} {{ article.title | escape }} {%- endfor -%}
{%- endif -%}

{%- endif -%}

You need to modify this code at the bottom (split into several lines for clarity):


    {{ 'search.form.search_for_html' | t: terms: predictive_search.terms }}

to become this:


    {{ 'search.form.search_for_html' | t: terms: predictive_search.terms }}

Basically the change is in href attribute.

It is not a change in search behaviour, it’s theme outputs mal-formed URL.

Thank you so much!!! It worked.