mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Gave search a friendly URL (/search)
- and changed the property on the view model from Term to Query (sounds better and goes with the 'q' param) --HG-- branch : dev
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Orchard.Search.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index(string q) {
|
public ActionResult Index(string q) {
|
||||||
var searchViewModel = new SearchViewModel {Term = q};
|
var searchViewModel = new SearchViewModel {Query = q};
|
||||||
|
|
||||||
var results = _searchService.Query(q);
|
var results = _searchService.Query(q);
|
||||||
searchViewModel.Results = results.Select(result => new SearchResultViewModel {
|
searchViewModel.Results = results.Select(result => new SearchResultViewModel {
|
||||||
|
@@ -67,6 +67,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controllers\SearchController.cs" />
|
<Compile Include="Controllers\SearchController.cs" />
|
||||||
<Compile Include="Filters\SearchFilter.cs" />
|
<Compile Include="Filters\SearchFilter.cs" />
|
||||||
|
<Compile Include="Routes.cs" />
|
||||||
<Compile Include="Services\ISearchService.cs" />
|
<Compile Include="Services\ISearchService.cs" />
|
||||||
<Compile Include="Services\SearchService.cs" />
|
<Compile Include="Services\SearchService.cs" />
|
||||||
<Compile Include="ViewModels\SearchResultViewModel.cs" />
|
<Compile Include="ViewModels\SearchResultViewModel.cs" />
|
||||||
|
34
src/Orchard.Web/Modules/Orchard.Search/Routes.cs
Normal file
34
src/Orchard.Web/Modules/Orchard.Search/Routes.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Routing;
|
||||||
|
using Orchard.Mvc.Routes;
|
||||||
|
|
||||||
|
namespace Orchard.Search {
|
||||||
|
public class Routes : IRouteProvider {
|
||||||
|
|
||||||
|
public void GetRoutes(ICollection<RouteDescriptor> routes) {
|
||||||
|
foreach (var routeDescriptor in GetRoutes())
|
||||||
|
routes.Add(routeDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<RouteDescriptor> GetRoutes() {
|
||||||
|
return new[] {
|
||||||
|
new RouteDescriptor {
|
||||||
|
Priority = 5,
|
||||||
|
Route = new Route(
|
||||||
|
"Search",
|
||||||
|
new RouteValueDictionary {
|
||||||
|
{"area", "Orchard.Search"},
|
||||||
|
{"controller", "search"},
|
||||||
|
{"action", "index"}
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
new RouteValueDictionary {
|
||||||
|
{"area", "Orchard.Search"}
|
||||||
|
},
|
||||||
|
new MvcRouteHandler())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,10 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Orchard.Indexing;
|
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Search.ViewModels {
|
namespace Orchard.Search.ViewModels {
|
||||||
public class SearchViewModel : BaseViewModel {
|
public class SearchViewModel : BaseViewModel {
|
||||||
public IEnumerable<SearchResultViewModel> Results { get; set; }
|
public IEnumerable<SearchResultViewModel> Results { get; set; }
|
||||||
public string Term { get; set; }
|
public string Query { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -5,7 +5,7 @@ Html.RegisterStyle("search.css"); %>
|
|||||||
<%
|
<%
|
||||||
Html.Zone("search"); %><%
|
Html.Zone("search"); %><%
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(Model.Term)) { %>
|
if (!string.IsNullOrWhiteSpace(Model.Query)) { %>
|
||||||
<p class="search-summary"><%=T("<em>{0}</em> results", Model.Results.Count()) %></p><%
|
<p class="search-summary"><%=T("<em>{0}</em> results", Model.Results.Count()) %></p><%
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
<%@ Import Namespace="Orchard.Search.ViewModels" %><%
|
<%@ Import Namespace="Orchard.Search.ViewModels" %><%
|
||||||
using(Html.BeginForm("index", "search", new { area = "Orchard.Search" }, FormMethod.Get, new { @class = "search" })) { %>
|
using(Html.BeginForm("index", "search", new { area = "Orchard.Search" }, FormMethod.Get, new { @class = "search" })) { %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<%=Html.TextBox("q", Model.Term) %>
|
<%=Html.TextBox("q", Model.Query) %>
|
||||||
<button type="submit"><%=T("Search") %></button>
|
<button type="submit"><%=T("Search") %></button>
|
||||||
</fieldset><%
|
</fieldset><%
|
||||||
} %>
|
} %>
|
Reference in New Issue
Block a user