From 3df43584cf0033c62547654136b7f3b0ace10617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Kottal?= Date: Thu, 10 Oct 2024 20:26:42 +0200 Subject: [PATCH] Adds search partial --- .../Views/Partials/Search.cshtml | 55 +++++++++++++++++++ .../Views/home.cshtml | 2 + 2 files changed, 57 insertions(+) create mode 100644 src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/Partials/Search.cshtml diff --git a/src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/Partials/Search.cshtml b/src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/Partials/Search.cshtml new file mode 100644 index 0000000..7a6e1a1 --- /dev/null +++ b/src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/Partials/Search.cshtml @@ -0,0 +1,55 @@ +@inject Our.Umbraco.FullTextSearch.Interfaces.ISearchService SearchService +@using Our.Umbraco.FullTextSearch.Models +@using System.Web +@using Umbraco.Extensions +@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage + + +
+
+
+ Search + + +
+
+ +@if (Context.Request.Query["q"].ToString() is string searchQuery && searchQuery.IsNullOrWhiteSpace() == false) +{ + var currentPage = int.TryParse(Context.Request.Query["p"], out var p) ? p : 1; + var search = new Search(searchQuery); + var results = SearchService.Search(search, currentPage); + +
+ Search Results for '@searchQuery' + +
@results.TotalResults results found
+
    + @foreach (var result in results.Results) + { +
  • +

    + + @result.Title + +

    +

    + @result.Summary +

    +

    Score: @result.Score

    +
  • + } +
+ + @if (currentPage > 1) + { + Previous page + } + @if (results.TotalPages > currentPage) + { + Next page + } +
+ +} +
\ No newline at end of file diff --git a/src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/home.cshtml b/src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/home.cshtml index a6167de..c2da91a 100644 --- a/src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/home.cshtml +++ b/src/Testsites/Our.Umbraco.FullTextSearch.Testsite14/Views/home.cshtml @@ -20,6 +20,8 @@ +@await Html.PartialAsync("Search") +
@await Html.GetBlockGridHtmlAsync(Model.BodyText)