Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello, I'm working on Search Results Pagination but i couldn't define the Search Term to use it in the pagination, here's my code;
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using System.Web.Mvc.Html @using Umbraco.Web @using UmbracoExamine @using Examine.LuceneEngine.SearchCriteria; @using Examine.LuceneEngine; @using Examine.LuceneEngine.Providers; @{ Layout = "Master.cshtml"; string term ="productName:" + Request.QueryString["searchTerm"] + "* productDes:"+ Request.QueryString["searchTerm"] +"*" ; //retrieve current page from query string int currentPage = 1; if (!String.IsNullOrEmpty(Request.QueryString["page"])) { int.TryParse(Request.QueryString["page"], out currentPage); } var noresults = false; //container for the searcher Examine.Providers.BaseSearchProvider searcher = null; //container for the results ISearchResults searchResults = null; //number of results var resultsCount = 0; //required results per page var pageSize = 10; if (Model.Content.HasValue("numberOfItemsPerPage")) { pageSize = Model.Content.GetPropertyValue<int>("numberOfItemsPerPage"); } } <div class="container"> <div class="row"> <div class="col-md-8"> <div class="searchedKeyword"> <span class="amman"></span> <span class="keyword">@term</span> </div> @{ if (term != null) { //now we need to work out which searcher to use //so we'll switch/case on the filter parameter in the querystring searcher = ExamineManager.Instance.SearchProviderCollection["productSearcher"]; //N.B. The following is REALLY basic but should get you started. It's this area where we could really go to town with Lucene. //create search criteria var searchCriteria = searcher.CreateSearchCriteria(); //pass the criteria our search term as a raw query var query = searchCriteria.RawQuery(term); //action a search based on our query searchResults = searcher.Search(query); resultsCount = searchResults.TotalItemCount; if (resultsCount < 1) { noresults = true; } } else { noresults = true; } if (noresults) { <div class="noresults media"> <h4> ! </h4> <h5> . </h5> </div> } else { //number of pages int totalPages = 1; if (resultsCount > pageSize) { totalPages = (int)Math.Ceiling((double)resultsCount / pageSize); if (currentPage > totalPages) { currentPage = totalPages; } else if (currentPage < 1) { currentPage = 1; } <div> @resultsCount results </div> <div> Page @currentPage of @totalPages pages </div> } //iterate the results //we could be clever here using linq queries but I want //to keep it simple, easily readable and understandable //for this exercise foreach (var searchResult in searchResults.Skip((currentPage - 1) * pageSize).Take(pageSize)) { @Html.Partial("ListproductItem", new ViewDataDictionary { { "productId", searchResult.Id } }) } <nav aria-label="Page navigation"> <ul class="pagination"> <li class="@(currentPage == 1 ? "disabled" : "")"> <a href="@(currentPage > 1 ? "/search-results?searchTerm=" + searchTerm + "&page=" + (currentPage - 1).ToString() : "#")" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> @for (var i = 1; i <= totalPages; i++) { <li> <a href="/search-results?term=@searchTerm &page=@i">@i</a> </li> } <li class="@(currentPage == totalPages ? "disabled" : "")"> <a href="@(currentPage < totalPages ? "/search-results?searchTerm=" + searchTerm + "&page=" + (currentPage + 1).ToString() : "#")" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav> } } </div> </div> </div>
The URL i'm getting from the code above showing below, which is not correct, (d) is the keyword that i searched for;
domain.com/search-results?searchTerm=productName:d*%20productDes:d*&page=1
And the right URL that i'm seeking as follows:
domain.com/search-results?searchTerm=d&page=1
Thanks indeed!
SOLVED, the code above is missing this line,
var searchTerm = Request["searchTerm"];
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Define Search Term in search results pagination
Hello, I'm working on Search Results Pagination but i couldn't define the Search Term to use it in the pagination, here's my code;
The URL i'm getting from the code above showing below, which is not correct, (d) is the keyword that i searched for;
And the right URL that i'm seeking as follows:
Thanks indeed!
SOLVED, the code above is missing this line,
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.