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
Hey everyone,
Would you please check my code and let me know what I'm missing to show the search results on the page?
My partial view macro file,
@using Examine.LuceneEngine.SearchCriteria @using System @using System.Linq @inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var searchQuery= Request.QueryString["query"]; if(String.IsNullOrWhiteSpace(searchQuery)) { searchQuery = ""; } var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]; var searchCriteria = searcher.CreateSearchCriteria(); var query = searchCriteria.GroupedOr( new []{"nodeName", "name", "title", "bodyText"},searchQuery).Compile(); var SearchResults = searcher.Search(query).Where(x => x["__IndexType"] == "content").ToList(); } @if (SearchResults.Any()) { <ul class="search-results-box"> @foreach (var result in SearchResults) { var node = Umbraco.TypedContent(result.Id); var pathIds = result["__Path"].Split(','); var path = Umbraco.TypedContent(pathIds).Where(p => p != null).Select(p => new { p.Name }).ToList(); if (node != null) { <div class="product col-sm-6 col-md-3 col-xs-6"> <a href="@node.Url" title="@node.Name">@node.Name</a> </div> } } </ul> } else { <p> @if(!String.IsNullOrWhiteSpace(searchQuery)) { <text> 'No results found for : @searchQuery</text> } </p> }
My Search Results page(Where I want to show the results);
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using ContentModels = Umbraco.Web.PublishedContentModels; @{ Layout = "Master.cshtml"; } <div class="container-fluid"> <div class="container"> <div class="row"> <div class="col-lg-6 pull-left"> @CurrentPage.bodyText </div> <div class="col-lg-offset-1"> </div> <div class="col-lg-3 pull-right"> </div> </div> </div> </div>
My Navigation page's related part for searching;
<div class="col-lg-3 input-group"> <form action="@Umbraco.Content(1149).Url()" method="post" target="_blank"> <input type="search" class="form-control" placeholder="Search" name="query" /> <span class="input-group-btn"><button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button></span> </form> </div>
I did the configuration on ~/config/ExamineSettings.config and ~/config/ExamineIndex.config
Used this link; https://our.umbraco.com/documentation/reference/searching/examine/quick-start
My macro is allowed in rich text editors and my text editor's alias is bodyText.
What am I missing?
(Ignore the styling, they are just for proper look)
have you checked there are records in the Examine index.. have a look at the developer tab and examine management..
Hey Ravi, Thanks for reply.
I've checked Examine Index and Examine settings on developer tab as well. It seem to not working still.
Still not seeing when I search something.
My searchResults page shows the body text but does not include the macro in there. Still confused.
Thanks in advance
okay next steps have you tried debugging it?? and stepping through to see if the search is a getting pages and then why its not displaying them..
I'll see if i can have a tinker later..
also is there any particular reason you are using a macro??
It doesn't seem like searching whatever I wrote in the
if(String.IsNullOrWhiteSpace(searchQuery)) { searchQuery = ""; } var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]; var searchCriteria = searcher.CreateSearchCriteria(); var query = searchCriteria.GroupedOr( new []{"nodeName", "name", "title", "bodyText"},searchQuery).Compile(); var SearchResults = searcher.Search(query).Where(x => x["__IndexType"] == "content").ToList(); } @if (SearchResults.Any()) { <ul class="search-results-box"> @foreach (var result in SearchResults) { var node = Umbraco.TypedContent(result.Id); var pathIds = result["__Path"].Split(','); var path = Umbraco.TypedContent(pathIds).Where(p => p != null).Select(p => new { p.Name }).ToList(); if (node != null) { <div class="product col-sm-6 col-md-3 col-xs-6"> <a href="@node.Url" title="@node.Name">@node.Name</a> </div> } } </ul> } else { <p> @if(!String.IsNullOrWhiteSpace(searchQuery)) { <text> 'No results found for : @searchQuery</text> } </p> }
It jumps straight to else no matter I search. Even though the words I am sure they are in the content.
I am so new in Umbraco, I am just fallowing a video set. But got stuck because I hate going on without solving the problem.
I saw other search methods but I really want to figure this out.
Thank you
so when you post the page to the macro you can see the search term in the macro
So
is posting and you can see that value in your macro here: var searchQuery= Request.QueryString["query"]; if(String.IsNullOrWhiteSpace(searchQuery)) { searchQuery = ""; }
No searchQuery doesn't carry the value I wrote
Fixed the problem. Took me a day and a half.
I changed
var searchQuery= Request.QueryString["query"];
to
string searchQuery= Request["query"];
Now It's working!!
Thanks for the help though :)
oh should have seen that.. so essentially your query was always null.. well done on getting there..
its always the same start with the basics and work up to the difficult
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
SearchResults with macro pages
Hey everyone,
Would you please check my code and let me know what I'm missing to show the search results on the page?
My partial view macro file,
My Search Results page(Where I want to show the results);
My Navigation page's related part for searching;
I did the configuration on ~/config/ExamineSettings.config and ~/config/ExamineIndex.config
Used this link; https://our.umbraco.com/documentation/reference/searching/examine/quick-start
My macro is allowed in rich text editors and my text editor's alias is bodyText.
What am I missing?
(Ignore the styling, they are just for proper look)
have you checked there are records in the Examine index.. have a look at the developer tab and examine management..
Hey Ravi, Thanks for reply.
I've checked Examine Index and Examine settings on developer tab as well. It seem to not working still.
Still not seeing when I search something.
My searchResults page shows the body text but does not include the macro in there. Still confused.
Thanks in advance
okay next steps have you tried debugging it?? and stepping through to see if the search is a getting pages and then why its not displaying them..
I'll see if i can have a tinker later..
also is there any particular reason you are using a macro??
It doesn't seem like searching whatever I wrote in the
It jumps straight to else no matter I search. Even though the words I am sure they are in the content.
I am so new in Umbraco, I am just fallowing a video set. But got stuck because I hate going on without solving the problem.
I saw other search methods but I really want to figure this out.
Thank you
so when you post the page to the macro you can see the search term in the macro
So
No searchQuery doesn't carry the value I wrote
Fixed the problem. Took me a day and a half.
I changed
to
Now It's working!!
Thanks for the help though :)
oh should have seen that.. so essentially your query was always null.. well done on getting there..
its always the same start with the basics and work up to the difficult
is working on a reply...