mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding Content Search in Admin
--HG-- branch : 1.x
This commit is contained in:
26
src/Orchard.Web/Modules/Orchard.Search/ContentAdminMenu.cs
Normal file
26
src/Orchard.Web/Modules/Orchard.Search/ContentAdminMenu.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Search {
|
||||
[OrchardFeature("Orchard.Search.Content")]
|
||||
public class ContentAdminMenu : INavigationProvider {
|
||||
public ContentAdminMenu() {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public string MenuName {
|
||||
get { return "admin"; }
|
||||
}
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.Add(T("Content"),
|
||||
menu => menu
|
||||
.Add(T("Search"), "1.5", item => item.Action("Index", "Admin", new {area = "Orchard.Search"}).LocalNav())
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
using Orchard.Localization;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Search {
|
||||
[OrchardFeature("Orchard.Search.ContentPicker")]
|
||||
public class ContentPickerNavigationProvider : INavigationProvider {
|
||||
public ContentPickerNavigationProvider() {
|
||||
T = NullLocalizer.Instance;
|
||||
|
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Collections;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Indexing;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Search.Models;
|
||||
using Orchard.Search.Services;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Search.Controllers {
|
||||
[OrchardFeature("Orchard.Search.Content")]
|
||||
public class AdminController : Controller {
|
||||
private readonly ISearchService _searchService;
|
||||
private readonly ISiteService _siteService;
|
||||
|
||||
public AdminController(
|
||||
IOrchardServices orchardServices,
|
||||
ISearchService searchService,
|
||||
ISiteService siteService) {
|
||||
_searchService = searchService;
|
||||
_siteService = siteService;
|
||||
Services = orchardServices;
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index(PagerParameters pagerParameters, string searchText = "") {
|
||||
Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
|
||||
var searchFields = Services.WorkContext.CurrentSite.As<SearchSettingsPart>().SearchedFields;
|
||||
|
||||
IPageOfItems<ISearchHit> searchHits = new PageOfItems<ISearchHit>(new ISearchHit[] { });
|
||||
try {
|
||||
|
||||
searchHits = _searchService.Query(searchText, pager.Page, pager.PageSize,
|
||||
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
|
||||
searchFields,
|
||||
searchHit => searchHit);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Logger.Error(T("Invalid search query: {0}", exception.Message).Text);
|
||||
Services.Notifier.Error(T("Invalid search query: {0}", exception.Message));
|
||||
}
|
||||
|
||||
var list = Services.New.List();
|
||||
foreach (var contentItem in searchHits.Select(searchHit => Services.ContentManager.Get(searchHit.ContentItemId))) {
|
||||
// ignore search results which content item has been removed or unpublished
|
||||
if (contentItem == null) {
|
||||
searchHits.TotalItemCount--;
|
||||
continue;
|
||||
}
|
||||
|
||||
list.Add(Services.ContentManager.BuildDisplay(contentItem, "SummaryAdmin"));
|
||||
}
|
||||
|
||||
var pagerShape = Services.New.Pager(pager).TotalItemCount(searchHits.TotalItemCount);
|
||||
|
||||
dynamic viewModel = Services.New.ViewModel()
|
||||
.ContentItems(list)
|
||||
.Pager(pagerShape)
|
||||
.SearchText(searchText);
|
||||
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)viewModel);
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ using System.Web.Mvc;
|
||||
using Orchard.Collections;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Indexing;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
@@ -18,6 +19,7 @@ using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Search.Controllers {
|
||||
[Admin]
|
||||
[OrchardFeature("Orchard.Search.ContentPicker")]
|
||||
public class ContentPickerController : Controller {
|
||||
private readonly ISearchService _searchService;
|
||||
private readonly ISiteService _siteService;
|
||||
|
@@ -5,6 +5,20 @@ Website: http://orchardproject.net
|
||||
Version: 1.4.1
|
||||
OrchardVersion: 1.4.1
|
||||
Description: The search module enables the management of the search index and provides the front-end searching user interface.
|
||||
FeatureDescription: Standard interface to Orchard's built-in search.
|
||||
Category: Search
|
||||
Dependencies: Orchard.Indexing
|
||||
|
||||
Features:
|
||||
Orchard.Search:
|
||||
Name: Search
|
||||
Description: Standard interface to Orchard's built-in search.
|
||||
Dependencies: Orchard.Indexing
|
||||
Category: Search
|
||||
Orchard.Search.Content:
|
||||
Name: Admin Content Search
|
||||
Description: Provides a Content Search tab in Admin.
|
||||
Dependencies: Contents
|
||||
Category: Search
|
||||
Orchard.Search.ContentPicker:
|
||||
Name: Content Picker Search
|
||||
Description: Provides a search tab in Content Picker.
|
||||
Dependencies: Orchard.ContentPicker
|
||||
Category: Search
|
||||
|
@@ -48,6 +48,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="ContentPickerNavigationProvider.cs" />
|
||||
<Compile Include="Controllers\ContentPickerController.cs" />
|
||||
<Compile Include="ContentAdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Drivers\SearchFormPartDriver.cs" />
|
||||
<Compile Include="Models\SearchFormPart.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
@@ -98,6 +100,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\SearchContentTab.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Admin\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
@@ -0,0 +1,21 @@
|
||||
@{
|
||||
var pageTitle = T("Search Content");
|
||||
Layout.Title = pageTitle;
|
||||
}
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
<label for="search-text">@T("Search")</label>
|
||||
@Html.TextBox("searchText", (string)Model.SearchText, new { @class = "text textMedium", autofocus = "autofocus" })
|
||||
|
||||
<button type="submit">@T("Search")</button>
|
||||
|
||||
<fieldset class="contentItems bulk-items">
|
||||
@Display(Model.ContentItems)
|
||||
</fieldset>
|
||||
|
||||
if (HasText(Model.SearchText) && Model.ContentItems.Items.Count == 0) {
|
||||
@T("There are no results")
|
||||
}
|
||||
|
||||
@Display(Model.Pager)
|
||||
}
|
@@ -6,7 +6,7 @@
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
<fieldset class="bulk-actions">
|
||||
<label for="search-text">@T("Search")</label>
|
||||
@Html.TextBox("searchText", (string)Model.SearchText, new { @class = "text", autofocus = "autofocus" })
|
||||
@Html.TextBox("searchText", (string)Model.SearchText, new { @class = "text textMedium", autofocus = "autofocus" })
|
||||
|
||||
<button type="submit">@T("Search")</button>
|
||||
</fieldset>
|
||||
|
Reference in New Issue
Block a user