Customizing Orchard.Search search results with alternates

Topics: Customizing Orchard, Writing themes
Apr 30, 2012 at 9:06 AM
Edited Apr 30, 2012 at 9:07 AM

I trying to customize search results returned by Orchard.Search.

I have created alternate in Theme\Views\Orchard.Search\Search\Index.cshtml, and it works ok:

 

@model Orchard.Search.ViewModels.SearchViewModel
@{
    Style.Require("Search");

    IEnumerable<object> searchResults = Model.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("search-results");
}
<h1>@Html.TitleForPage(T("Search").Text)</h1>

@if (HasText(Model.Query)) {
    if (searchResults.Count() == 0) { 
        <p class="search-summary">@T.Plural("There is <em>one</em> result", "<em>zero</em> results", searchResults.Count())</p>
    } else { 
        <p class="search-summary">@T.Plural("There is <em>one</em> result", "<em>{1} - {2}</em> of <em>{0}</em> results", Model.TotalItemCount, Model.StartPosition, Model.EndPosition)</p>
    }
}
@if (searchResults != null && searchResults.Count() > 0) {
    @Display(searchResults)
    @Display(Model.Pager)
}

 

But it seems that @Display(searchResults) renders each item using Core\Contents\Views\Content.Summary.cshtml and next Core\Common\Parts.Common.Body.Summary.cshtml, and I have no idea how to create alternates of them only for search results.

Any help will be appreciated!


Coordinator
Apr 30, 2012 at 5:11 PM

searchResults is just an enumeration of shapes. Each of them has a Metadata property, on which you can find and change the DisplayType, or even add to the Alternates collection on the fly.

May 2, 2012 at 8:34 AM

 

bertrandleroy,

I had to both add new DisplayType and new Alternate into Metadata for correct tracing. Now it is working ok. 

Thank you very much!