Supporting custom display type for search results

This commit is contained in:
Sebastien Ros
2015-09-09 15:44:53 -07:00
parent e839f84537
commit 80b93e412a
5 changed files with 15 additions and 2 deletions

View File

@@ -73,7 +73,7 @@ namespace Orchard.Search.Controllers {
// ignore search results which content item has been removed or unpublished
var foundItems = _contentManager.GetMany<IContent>(foundIds, VersionOptions.Published, new QueryHints()).ToList();
foreach (var contentItem in foundItems) {
list.Add(_contentManager.BuildDisplay(contentItem, "Summary"));
list.Add(_contentManager.BuildDisplay(contentItem, searchSettingPart.DisplayType));
}
searchHits.TotalItemCount -= foundIds.Count() - foundItems.Count();

View File

@@ -34,11 +34,14 @@ namespace Orchard.Search.Drivers {
var model = new SearchSettingsViewModel();
var searchFields = part.SearchFields;
model.DisplayType = part.DisplayType;
if (updater != null) {
if (updater.TryUpdateModel(model, Prefix, null, null)) {
part.SearchIndex = model.SelectedIndex;
part.SearchFields = model.Entries.ToDictionary(x => x.Index, x => x.Fields.Where(e => e.Selected).Select(e => e.Field).ToArray());
part.FilterCulture = model.FilterCulture;
part.DisplayType = model.DisplayType;
}
}
else if (_indexManager.HasIndexProvider()) {

View File

@@ -24,5 +24,10 @@ namespace Orchard.Search.Models {
get { return this.Retrieve(x => x.SearchIndex); }
set { this.Store(x => x.SearchIndex, value); }
}
public string DisplayType {
get { return this.Retrieve(x => x.DisplayType, "Summary"); }
set { this.Store(x => x.DisplayType, value); }
}
}
}

View File

@@ -9,6 +9,7 @@ namespace Orchard.Search.ViewModels {
public string SelectedIndex { get; set; }
public IList<IndexSettingsEntry> Entries { get; set; }
public bool FilterCulture { get; set; }
public string DisplayType { get; set; }
}
public class IndexSettingsEntry {

View File

@@ -57,5 +57,9 @@
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.FilterCulture)">@T("Narrow search to current culture only")</label>
<span class="hint">@T("If checked, search results will only include content items localized in the current culture of the request.")</span>
</div>
<div>
<label for="@Html.FieldIdFor(m => m.DisplayType)">@T("Display Type")</label>
@Html.TextBoxFor(m => m.DisplayType, new { @class = "text single-line" })
<span class="hint">@T("The display type to use for content items in the search results page.")</span>
</div>
</fieldset>