From b4eade4d4d9bb925e185a0d7de9a3ff4cb93daf2 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Thu, 3 Jun 2010 14:04:50 -0700 Subject: [PATCH] Start of the search UI - includes a single search/results page (URL needs to change, currently @ /Search/Search when the feature is enabled) --HG-- branch : dev --- .../Controllers/SearchController.cs | 28 +++++ .../Modules/Orchard.Search/Module.txt | 11 ++ .../Orchard.Search/Orchard.Search.csproj | 117 ++++++++++++++++++ .../Orchard.Search/Properties/AssemblyInfo.cs | 35 ++++++ .../Orchard.Search/Services/ISearchService.cs | 8 ++ .../Orchard.Search/Services/SearchService.cs | 25 ++++ .../Modules/Orchard.Search/Styles/search.css | 18 +++ .../ViewModels/SearchResultViewModel.cs | 9 ++ .../ViewModels/SearchViewModel.cs | 10 ++ .../Orchard.Search/Views/Search/Index.ascx | 15 +++ .../Modules/Orchard.Search/Views/Web.config | 34 +++++ .../Modules/Orchard.Search/Web.config | 60 +++++++++ src/Orchard.Web/Orchard.Web.csproj | 4 + src/Orchard.sln | 9 +- 14 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Module.txt create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Properties/AssemblyInfo.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Services/ISearchService.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Styles/search.css create mode 100644 src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchResultViewModel.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.ascx create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Views/Web.config create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Web.config diff --git a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs new file mode 100644 index 000000000..01f690dbc --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs @@ -0,0 +1,28 @@ +using System.Linq; +using System.Web.Mvc; +using Orchard.ContentManagement; +using Orchard.Search.Services; +using Orchard.Search.ViewModels; + +namespace Orchard.Search.Controllers { + public class SearchController : Controller { + private readonly ISearchService _searchService; + private readonly IContentManager _contentManager; + + public SearchController(ISearchService searchService, IContentManager contentManager) { + _searchService = searchService; + _contentManager = contentManager; + } + + public ActionResult Index(string term) { + var results = _searchService.Query(term); + return View(new SearchViewModel { + Term = term, + Results = results.Select(result => new SearchResultViewModel { + Content = _contentManager.BuildDisplayModel(_contentManager.Get(result.Id), "SummaryForSearch"), + SearchHit = result + }).ToList() + }); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Module.txt b/src/Orchard.Web/Modules/Orchard.Search/Module.txt new file mode 100644 index 000000000..9aaf4589a --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Module.txt @@ -0,0 +1,11 @@ +name: Search +antiforgery: enabled +author: The Orchard Team +website: http://orchardproject.net +version: 0.1 +orchardversion: 0.1.2010.0312 +description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ut arcu turpis, et placerat nunc. Nunc sollicitudin iaculis est, in ultricies mi facilisis et. Aenean et tortor non metus adipiscing laoreet in a justo. Pellentesque faucibus nisl ac lectus mollis quis pellentesque tortor egestas. Curabitur vel velit semper nunc gravida scelerisque. Vivamus at tellus dolor, in ultrices quam posuere. +features: + Orchard.Search: + Description: Standard interface to Orchard's built-in search. + Category: Search \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj b/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj new file mode 100644 index 000000000..52d210945 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj @@ -0,0 +1,117 @@ + + + + Debug + AnyCPU + + + 2.0 + {4BE4EB01-AC56-4048-924E-2CA77F509ABA} + {F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Orchard.Search + Orchard.Search + v4.0 + false + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + + + + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + 3.5 + + + + 3.5 + + + + + + + + + + + + + + + + + + + {2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6} + Orchard.Framework + + + + + + + + + + + + + + + + + + + + + + False + True + 47866 + / + + + False + True + http://orchard.codeplex.com + False + + + + + \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Properties/AssemblyInfo.cs b/src/Orchard.Web/Modules/Orchard.Search/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..fb34f0f84 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Orchard.Search")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Orchard.Search")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fa37585c-b84e-4b5b-a7da-13692ff45a94")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Orchard.Web/Modules/Orchard.Search/Services/ISearchService.cs b/src/Orchard.Web/Modules/Orchard.Search/Services/ISearchService.cs new file mode 100644 index 000000000..490fcc31c --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Services/ISearchService.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using Orchard.Indexing; + +namespace Orchard.Search.Services { + public interface ISearchService : IDependency { + IEnumerable Query(string term); + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs b/src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs new file mode 100644 index 000000000..58069d0df --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Linq; +using Orchard.Indexing; + +namespace Orchard.Search.Services +{ + public class SearchService : ISearchService + { + private readonly IIndexProvider _indexProvider; + + public SearchService(IIndexProvider indexProvider) { + _indexProvider = indexProvider; + } + + public IEnumerable Query(string term) { + if (string.IsNullOrWhiteSpace(term)) + return Enumerable.Empty(); + + return _indexProvider.CreateSearchBuilder("search") + .WithField("title", term) + .WithField("body", term) + .Search(); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Styles/search.css b/src/Orchard.Web/Modules/Orchard.Search/Styles/search.css new file mode 100644 index 000000000..3240b4d1c --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Styles/search.css @@ -0,0 +1,18 @@ +form.search { + float:left; +} +form.search input { + display:inline; + width:20em; +} +.search-summary { + float:right; + font-style:italic; + margin-top:0; +} +.search-summary em { + font-weight:bold; +} +.search-results { + clear:both; +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchResultViewModel.cs b/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchResultViewModel.cs new file mode 100644 index 000000000..15e66c0b4 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchResultViewModel.cs @@ -0,0 +1,9 @@ +using Orchard.Indexing; +using Orchard.Mvc.ViewModels; + +namespace Orchard.Search.ViewModels { + public class SearchResultViewModel { + public ISearchHit SearchHit { get; set; } + public ContentItemViewModel Content { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs b/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs new file mode 100644 index 000000000..c01903cf8 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using Orchard.Indexing; +using Orchard.Mvc.ViewModels; + +namespace Orchard.Search.ViewModels { + public class SearchViewModel : BaseViewModel { + public IEnumerable Results { get; set; } + public string Term { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.ascx b/src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.ascx new file mode 100644 index 000000000..2fbc3158e --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.ascx @@ -0,0 +1,15 @@ +<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> +<%@ Import Namespace="Orchard.Mvc.Html" %><% +Html.RegisterStyle("search.css"); %> +

<%=Html.TitleForPage(T("Search"))%>

<% +using(Html.BeginForm("index", "search", FormMethod.Get, new { @class = "search" })) { %> +
+ <%=Html.TextBoxFor(m => m.Term) %> + +
<% +} + +if (Model.Results.Count() > 0) { %> +

<%=T("{0} results", Model.Results.Count()) %>

+ <%=Html.UnorderedList(Model.Results, (r, i) => Html.DisplayForItem(r.Content).ToHtmlString(), "search-results contentItems") %><% +} %> \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Views/Web.config b/src/Orchard.Web/Modules/Orchard.Search/Views/Web.config new file mode 100644 index 000000000..e065d8735 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Views/Web.config @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Orchard.Web/Modules/Orchard.Search/Web.config b/src/Orchard.Web/Modules/Orchard.Search/Web.config new file mode 100644 index 000000000..c654951f1 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Web.config @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Orchard.Web/Orchard.Web.csproj b/src/Orchard.Web/Orchard.Web.csproj index 92a1b60ed..2da25214d 100644 --- a/src/Orchard.Web/Orchard.Web.csproj +++ b/src/Orchard.Web/Orchard.Web.csproj @@ -155,6 +155,10 @@ {D10AD48F-407D-4DB5-A328-173EC7CB010F} Orchard.Roles + + {4BE4EB01-AC56-4048-924E-2CA77F509ABA} + Orchard.Search + {8C7FCBC2-E6E1-405E-BFB5-D8D9E67A09C4} Orchard.Setup diff --git a/src/Orchard.sln b/src/Orchard.sln index 7337aa9e1..c1b3aa847 100644 --- a/src/Orchard.sln +++ b/src/Orchard.sln @@ -65,6 +65,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Profile", "Orchard. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.MetaData", "Orchard.Web\Modules\Orchard.MetaData\Orchard.MetaData.csproj", "{23E04990-2A8D-41B8-9908-6DDB71EA3B23}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Search", "Orchard.Web\Modules\Orchard.Search\Orchard.Search.csproj", "{4BE4EB01-AC56-4048-924E-2CA77F509ABA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -183,12 +185,15 @@ Global {23E04990-2A8D-41B8-9908-6DDB71EA3B23}.Debug|Any CPU.Build.0 = Debug|Any CPU {23E04990-2A8D-41B8-9908-6DDB71EA3B23}.Release|Any CPU.ActiveCfg = Release|Any CPU {23E04990-2A8D-41B8-9908-6DDB71EA3B23}.Release|Any CPU.Build.0 = Release|Any CPU + {4BE4EB01-AC56-4048-924E-2CA77F509ABA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4BE4EB01-AC56-4048-924E-2CA77F509ABA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4BE4EB01-AC56-4048-924E-2CA77F509ABA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4BE4EB01-AC56-4048-924E-2CA77F509ABA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {94E694A2-D140-468D-A277-C5FCE1D13E9B} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA} {954CA994-D204-468B-9D69-51F6AD3E1C29} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} {D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} {79AED36E-ABD0-4747-93D3-8722B042454B} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} @@ -204,11 +209,13 @@ Global {CDE24A24-01D3-403C-84B9-37722E18DFB7} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} {17F86780-9A1F-4AA1-86F1-875EEC2730C7} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} {23E04990-2A8D-41B8-9908-6DDB71EA3B23} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} + {4BE4EB01-AC56-4048-924E-2CA77F509ABA} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5} {ABC826D4-2FA1-4F2F-87DE-E6095F653810} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA} {F112851D-B023-4746-B6B1-8D2E5AD8F7AA} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA} {6CB3EB30-F725-45C0-9742-42599BA8E8D2} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA} {2FC1D9C8-446D-4414-B252-5E9FBE61EB63} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA} {7354DF37-934B-46CF-A13C-455D5F5F5413} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA} + {94E694A2-D140-468D-A277-C5FCE1D13E9B} = {74E681ED-FECC-4034-B9BD-01B0BB1BDECA} {5E5E7A21-C7B2-44D8-8593-2F9541AE041D} = {383DBA32-4A3E-48D1-AAC3-75377A694452} {4AB4B5B6-277E-4FF6-B69B-7AE9E16D2A56} = {383DBA32-4A3E-48D1-AAC3-75377A694452} {33B1BC8D-E292-4972-A363-22056B207156} = {383DBA32-4A3E-48D1-AAC3-75377A694452}