Skip to content

Commit

Permalink
Resolves #1172 Search: Option to display related search terms on sear…
Browse files Browse the repository at this point in the history
…ch page
  • Loading branch information
mgesing committed Sep 20, 2018
1 parent 21b31ea commit 7875f39
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Expand Up @@ -16,7 +16,9 @@
* Added option to add multiple file versions to product download section
* Added options for alternating price display (in badges)
* Added option to display a captcha on forum pages when creating or replying to a topic.
* MegaSearch: Supports searching for forum posts.
* **MegaSearch**:
* Supports searching for forum posts.
* #1172 Option to display related search terms on search page.
* Customer avatar: Letter with colored background if no avatar image was uploaded.
* Viveum: Supports payment via "Virtual Account Brands" like PayPal.

Expand Down
Expand Up @@ -505,6 +505,10 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
builder.AddOrUpdate("Admin.Catalog.Products.BundleItems.NoProductLinkageForBundleItem",
"The type cannot be changed to \"Product\" because the product \"{0}\" is bundle item of a product bundle.",
"Der Typ kann nicht in \"Produkt\" geändert werden, weil das Produkt \"{0}\" auf der Stückliste eines Produkt-Bundle steht.");

builder.AddOrUpdate("Search.RelatedSearchTerms",
"Related search terms",
"Verwandte Suchbegriffe");
}
}
}
Expand Up @@ -1802,8 +1802,6 @@ public ActionResult Search(ForumSearchQuery query)

PrepareSearchResult(model, null);

model.AddSpellCheckerSuggestions(model.SearchResult.SpellCheckerSuggestions, T, x => Url.RouteUrl("BoardSearch", new { q = x }));

return View(model);
}

Expand Down
27 changes: 12 additions & 15 deletions src/Presentation/SmartStore.Web/Controllers/SearchController.cs
Expand Up @@ -70,9 +70,11 @@ public ActionResult SearchBox()

[HttpPost, ValidateInput(false)]
public ActionResult InstantSearch(CatalogSearchQuery query)
{
if (string.IsNullOrWhiteSpace(query.Term) || query.Term.Length < _searchSettings.InstantSearchTermMinLength)
return Content(string.Empty);
{
if (string.IsNullOrWhiteSpace(query.Term) || query.Term.Length < _searchSettings.InstantSearchTermMinLength)
{
return Content(string.Empty);
}

query
.BuildFacetMap(false)
Expand All @@ -97,12 +99,10 @@ public ActionResult InstantSearch(CatalogSearchQuery query)
mappingSettings.MapPictures = _searchSettings.ShowProductImagesInInstantSearch;
mappingSettings.ThumbnailSize = _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage;

var summaryModel = _catalogHelper.MapProductSummaryModel(result.Hits, mappingSettings);

// Add product hits
model.TopProducts = summaryModel;
// Add product hits.
model.TopProducts = _catalogHelper.MapProductSummaryModel(result.Hits, mappingSettings);

// Add spell checker suggestions (if any)
// Add spell checker suggestions (if any).
model.AddSpellCheckerSuggestions(result.SpellCheckerSuggestions, T, x => Url.RouteUrl("Search", new { q = x }));

return PartialView(model);
Expand Down Expand Up @@ -131,9 +131,9 @@ public ActionResult Search(CatalogSearchQuery query)
{
result = _catalogSearchService.Search(query);
}
catch (Exception exception)
catch (Exception ex)
{
model.Error = exception.ToString();
model.Error = ex.ToString();
result = new CatalogSearchResult(query);
}

Expand Down Expand Up @@ -166,15 +166,12 @@ public ActionResult Search(CatalogSearchQuery query)
var mappingSettings = _catalogHelper.GetBestFitProductSummaryMappingSettings(query.GetViewMode());
var summaryModel = _catalogHelper.MapProductSummaryModel(result.Hits, mappingSettings);

// Prepare paging/sorting/mode stuff
// Prepare paging/sorting/mode stuff.
_catalogHelper.MapListActions(summaryModel, null, _catalogSettings.DefaultPageSizeOptions);

// Add product hits
// Add product hits.
model.TopProducts = summaryModel;

// Add spell checker suggestions (if any)
model.AddSpellCheckerSuggestions(result.SpellCheckerSuggestions, T, x => Url.RouteUrl("Search", new { q = x }));

return View(model);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Presentation/SmartStore.Web/Views/Boards/Search.cshtml
Expand Up @@ -36,15 +36,15 @@
</div>

<div class="page-body">
<div class="search-input mt-4 mb-5">
<div class="search-input mt-4">
@if (Model.AllowFiltering && Model.SearchResult.Facets.Any())
{
<div class="mb-4">
@{ Html.RenderAction("Filters", new { model = Model }); }
</div>
}

<div class="w-75 mb-2">
<div class="w-75 mb-4">
@{ Html.RenderAction("SearchBox", "Boards"); }
</div>

Expand All @@ -68,10 +68,10 @@
</div>
}

@if (suggestions.Any() && (Model.AttemptedTerm.HasValue() || Model.TotalCount == 0))
@if (suggestions.Any())
{
<p class="search-suggestions">
<strong>@T("Search.DidYouMean")</strong>
<strong>@(T(Model.AttemptedTerm.HasValue() || Model.TotalCount == 0 ? "Search.DidYouMean" : "Search.RelatedSearchTerms")):</strong>
@{
var links = string.Join(", ", suggestions.Select(x => "<a href='" + Url.RouteUrl("BoardSearch", new { q = x }) + "'>{0}</a>".FormatCurrentUI(x)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Presentation/SmartStore.Web/Views/Search/Search.cshtml
Expand Up @@ -75,10 +75,10 @@
</div>
}

@if (suggestions.Any() && (Model.AttemptedTerm.HasValue() || Model.TotalProductsCount == 0))
@if (suggestions.Any())
{
<p class="search-suggestions">
<strong>@T("Search.DidYouMean")</strong>
<strong>@(T(Model.AttemptedTerm.HasValue() || Model.TotalProductsCount == 0 ? "Search.DidYouMean" : "Search.RelatedSearchTerms")):</strong>
@{
var links = String.Join(", ", suggestions.Select(x => "<a href='" + Url.RouteUrl("Search", new { q = x }) + "'>{0}</a>".FormatCurrentUI(x)));
}
Expand Down

0 comments on commit 7875f39

Please sign in to comment.