Skip to content

Commit

Permalink
SU-946 , SU-945 ; Spell correction with autocorrect and did-you-mean (#…
Browse files Browse the repository at this point in the history
…377)

* SU-1094: Add auto-correct and did-you-mean for search-results
* SU-1100: Add Did-You-Mean for Search Results (#371)
  • Loading branch information
kibo-paultheron committed Oct 13, 2021
1 parent 8904b83 commit 307ee76
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
2 changes: 2 additions & 0 deletions labels/de-DE.json
Expand Up @@ -606,6 +606,8 @@
"searchByAddress": "Suche nach Adresse",
"searchExpirationDate": "Ablaufdatum der Suche",
"searchResults": "Suchergebnisse",
"searchResultsAutocorrected": "Es werden Ergebnisse gezeigt für",
"searchResultsDidyoumean": "Meinten Sie",
"searchResultsSummary": "Ihre Suche nach \"{0}\" im {1} ergab {2} Ergebnisse. <a href=\"#\" data-mz-action=\"expandSearch\">Wiederholen Sie diese Suche in allen Kategorien.</a>",
"searchTitle": "Suchergebnisse für {0}",
"securityCode": "Sicherheitscode",
Expand Down
2 changes: 2 additions & 0 deletions labels/en-US.json
Expand Up @@ -719,6 +719,8 @@
"searchByAddress": "Search by Address",
"searchExpirationDate": "Search Expiration Date",
"searchResults": "Search Results",
"searchResultsAutocorrected": "Showing results for",
"searchResultsDidyoumean": "Did you mean",
"searchResultsSummary": "Your search for \"{0}\" within {1} returned {2} results. <a href=\"#\" data-mz-action=\"expandSearch\">Repeat this search across all categories.</a>",
"searchTitle": "Search Results for {0}",
"securityCode": "Security Code (CVV2)",
Expand Down
12 changes: 12 additions & 0 deletions templates/modules/search/did-you-mean.hypr.live
@@ -0,0 +1,12 @@
<div class="mz-did-you-mean">
{% with model.spellcheck.candidateCorrections|first as firstCandidate %}
{% if firstCandidate.query %}
<h2>
<span>{{ labels.searchResultsDidyoumean }}:</span>
<a href="{% make_url "search" with query=firstCandidate.query and spellcorrectOverride='skipall' as_parameters %}">
{{ firstCandidate.query }}
</a>
</h2>
{% endif %}
{% endwith %}
</div>
2 changes: 2 additions & 0 deletions templates/pages/no-search-results.hypr
Expand Up @@ -9,6 +9,8 @@
<div class="mz-l-container">
<h1 class="mz-pagetitle">{{ labels.noResults }}: <span class="mz-searchresults-query">{{ pageContext.search.query }}</span></h1>

{% include "modules/search/did-you-mean" %}

<p class="mz-searchresults-noresultstext">{{ labels.noResultsText }}</p>

{% dropzone "no-results" scope="template" %}
Expand Down
24 changes: 19 additions & 5 deletions templates/pages/search-interior.hypr
@@ -1,5 +1,19 @@
<h1 class="mz-pagetitle">{{ labels.searchResults }}: <span class="mz-searchresults-query">{{ pageContext.search.query }}</span></h1>
{% partial_cache model.categoryId pageContext.Sorting pageContext.Pagination pageContext.query.sortBy pageContext.search.query %}
{% include "modules/product/faceted-products" %}
{% endpartial_cache %}
{% dropzone "search-results" scope="template" %}
{% if model.spellcheck.autoCorrected %}
<h1 class="mz-pagetitle">{{ labels.searchResultsAutocorrected }}: <span class="mz-searchresults-query">{{ model.spellcheck.correctedQuery }}</span></h1>
{% else %}
<h1 class="mz-pagetitle">{{ labels.searchResults }}: <span class="mz-searchresults-query">{{ pageContext.search.query }}</span></h1>
{% endif %}

{% include "modules/search/did-you-mean" %}

{% if model.spellcheck.autoCorrected %}
{% partial_cache model.categoryId pageContext.Sorting pageContext.Pagination pageContext.query.sortBy model.spellcheck.correctedQuery %}
{% include "modules/product/faceted-products" %}
{% endpartial_cache %}
{% else %}
{% partial_cache model.categoryId pageContext.Sorting pageContext.Pagination pageContext.query.sortBy pageContext.search.query %}
{% include "modules/product/faceted-products" %}
{% endpartial_cache %}
{% endif %}

{% dropzone "search-results" scope="template" %}
21 changes: 12 additions & 9 deletions templates/pages/search-results.hypr
@@ -1,16 +1,19 @@
{% extends "page" %}

{% block title-tag-content %}{{ labels.searchTitle|string_format(pageContext.search.query) }} - {% parent %}{% endblock title-tag-content %}
{% block title-tag-content %}
{% if model.spellcheck.autoCorrected %}
{{ labels.searchTitle|string_format(model.spellcheck.correctedQuery) }} - {% parent %}
{% else %}
{{ labels.searchTitle|string_format(pageContext.search.query) }} - {% parent %}
{% endif %}
{% endblock title-tag-content %}

{% block body-tag-classes %} mz-searchresults {% endblock body-tag-classes %}

{% block body-content %}

{% require_script "pages/search" %}

<div {% if pageContext.categoryId %}data-mz-category="{{ pageContext.categoryId }}" {% endif %}data-mz-search="{{ pageContext.search.query }}" class="mz-l-container">
{% include "pages/search-interior" %}
</div>

{% require_script "pages/search" %}
<div {% if pageContext.categoryId %}data-mz-category="{{ pageContext.categoryId }}" {% endif %}
data-mz-search="{% firstof model.spellcheck.CorrectedQuery pageContext.search.query %}" class="mz-l-container">
{% include "pages/search-interior" %}
</div>
{% endblock body-content %}

0 comments on commit 307ee76

Please sign in to comment.