Customizing Orchard.Search search results with alternates

Topics: Customizing Orchard, Writing themes
Apr 30, 2012 at 8:06 AM
Edited Apr 30, 2012 at 8: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

    IEnumerable<object> searchResults = Model.ContentItems;

@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) {


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!

Apr 30, 2012 at 4: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 7:34 AM



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

Thank you very much!