Skip to content

Commit 6f9fdab

Browse files
committed
Search: More on forum search
1 parent d0d0b79 commit 6f9fdab

8 files changed

Lines changed: 54 additions & 29 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace SmartStore.Core.Domain.Forums
2+
{
3+
public enum ForumDateFilter
4+
{
5+
LastVisit = 1,
6+
Yesterday,
7+
LastWeek,
8+
LastTwoWeeks,
9+
LastMonth,
10+
LastThreeMonths,
11+
LastSixMonths,
12+
LastYear
13+
}
14+
}

src/Libraries/SmartStore.Core/Domain/Forums/ForumTopicSorting.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ public enum ForumTopicSorting
2525
/// </summary>
2626
SubjectDesc,
2727

28+
/// <summary>
29+
/// User name: A to Z
30+
/// </summary>
31+
UserNameAsc,
32+
33+
/// <summary>
34+
/// User name: Z to A
35+
/// </summary>
36+
UserNameDesc,
37+
2838
/// <summary>
2939
/// Creation date: Oldest first
3040
/// </summary>
@@ -43,16 +53,6 @@ public enum ForumTopicSorting
4353
/// <summary>
4454
/// Number of posts: High to Low
4555
/// </summary>
46-
PostsDesc,
47-
48-
/// <summary>
49-
/// Number of views: Low to High
50-
/// </summary>
51-
ViewsAsc,
52-
53-
/// <summary>
54-
/// Number of views: High to Low
55-
/// </summary>
56-
ViewsDesc
56+
PostsDesc
5757
}
5858
}

src/Libraries/SmartStore.Core/Search/Settings/ForumSearchSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ForumSearchSettings : ISettings
99
public ForumSearchSettings()
1010
{
1111
SearchMode = SearchMode.Contains;
12-
SearchFields = new List<string> { "subject" };
12+
SearchFields = new List<string> { "subject", "username" };
1313
TopicSortOrder = ForumTopicSorting.Relevance;
1414
InstantSearchEnabled = true;
1515
InstantSearchNumberOfHits = 10;

src/Libraries/SmartStore.Core/SmartStore.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
<Compile Include="Domain\DataExchange\ExportEnums.cs" />
233233
<Compile Include="Domain\DataExchange\ExportFilter.cs" />
234234
<Compile Include="Domain\DataExchange\ExportProfile.cs" />
235+
<Compile Include="Domain\Forums\ForumDateFilter.cs" />
235236
<Compile Include="Domain\Forums\ForumTopicSorting.cs" />
236237
<Compile Include="Domain\Media\MediaStorage.cs" />
237238
<Compile Include="Domain\Media\IHasMedia.cs" />

src/Libraries/SmartStore.Data/Migrations/MigrationsConfiguration.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,26 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
373373

374374
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.Initial", "Position", "Position");
375375
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.Relevance", "Relevance", "Beste Ergebnisse");
376-
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.SubjectAsc", "Subject: A to Z", "Thema: A bis Z");
377-
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.SubjectDesc", "Subject: Z to A", "Thema: Z bis A");
376+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.SubjectAsc", "Title: A to Z", "Titel: A bis Z");
377+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.SubjectDesc", "Title: Z to A", "Titel: Z bis A");
378+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.UserNameAsc", "User name: A to Z", "Benutzername: A bis Z");
379+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.UserNameDesc", "User name: Z to A", "Benutzername: Z bis A");
378380
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.CreatedOnAsc", "Created on: Oldest first", "Erstellt am: ältere zuerst");
379381
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.CreatedOnDesc", "Created on: Newest first", "Erstellt am: neuere zuerst");
380382
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.PostsAsc", "Post number: ascending", "Anzahl Beiträge: aufsteigend");
381383
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.PostsDesc", "Post number: descending", "Anzahl Beiträge: absteigend");
382-
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.ViewsAsc", "Hits number: ascending", "Trefferanzahl: aufsteigend");
383-
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumTopicSorting.ViewsDesc", "Hits number: descending", "Trefferanzahl: absteigend");
384+
385+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.LastVisit", "Since last visit", "Seit dem letzten Besuch");
386+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.Yesterday", "Yesterday", "Gestern");
387+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.LastWeek", "Last week", "In der letzten Woche");
388+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.LastTwoWeeks", "Last 2 weeks", "In den letzten 2 Wochen");
389+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.LastMonth", "Last month", "Im letzten Monat");
390+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.LastThreeMonths", "Last 3 months", "In den letzten 3 Monaten");
391+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.LastSixMonths", "Last 6 months", "In den letzten 6 Monaten");
392+
builder.AddOrUpdate("Enums.SmartStore.Core.Domain.Forums.ForumDateFilter.LastYear", "Last year", "Im letzten Jahr");
384393

385394
builder.AddOrUpdate("Search.Facet.Forum", "Forum", "Forum");
386-
builder.AddOrUpdate("Search.Facet.Customer", "Customer", "Kunde");
395+
builder.AddOrUpdate("Search.Facet.Customer", "Name", "Name");
387396
builder.AddOrUpdate("Search.Facet.Date", "Date", "Datum");
388397

389398
builder.AddOrUpdate("Admin.Configuration.Settings.Search.WildcardSearchNote",

src/Libraries/SmartStore.Services/Search/Forum/ForumSearchQuery.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public ForumSearchQuery SortBy(ForumTopicSorting sort)
4545
case ForumTopicSorting.SubjectDesc:
4646
return SortBy(SearchSort.ByStringField("subject", sort == ForumTopicSorting.SubjectDesc));
4747

48+
case ForumTopicSorting.UserNameAsc:
49+
case ForumTopicSorting.UserNameDesc:
50+
return SortBy(SearchSort.ByStringField("username", sort == ForumTopicSorting.UserNameDesc));
51+
4852
case ForumTopicSorting.CreatedOnAsc:
4953
case ForumTopicSorting.CreatedOnDesc:
5054
return SortBy(SearchSort.ByDateTimeField("createdon", sort == ForumTopicSorting.CreatedOnDesc));
@@ -53,10 +57,6 @@ public ForumSearchQuery SortBy(ForumTopicSorting sort)
5357
case ForumTopicSorting.PostsDesc:
5458
return SortBy(SearchSort.ByIntField("numposts", sort == ForumTopicSorting.PostsDesc));
5559

56-
case ForumTopicSorting.ViewsAsc:
57-
case ForumTopicSorting.ViewsDesc:
58-
return SortBy(SearchSort.ByIntField("views", sort == ForumTopicSorting.ViewsDesc));
59-
6060
case ForumTopicSorting.Relevance:
6161
return SortBy(SearchSort.ByRelevance());
6262

src/Libraries/SmartStore.Services/Search/Forum/LinqForumSearchService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ protected virtual IQueryable<ForumTopic> GetForumTopicQuery(ForumSearchQuery sea
4444
var filters = new List<ISearchFilter>();
4545
var query = baseQuery ?? _forumPostRepository.Table.Expand(x => x.ForumTopic);
4646

47-
//var searchType = ForumSearchType.All; //TODO, obsolete?
48-
4947
// Apply search term.
5048
if (term.HasValue() && fields != null && fields.Length != 0 && fields.Any(x => x.HasValue()))
5149
{
5250
if (searchQuery.Mode == SearchMode.StartsWith)
5351
{
5452
query = query.Where(x =>
5553
(fields.Contains("subject") && x.ForumTopic.Subject.StartsWith(term)) ||
54+
(fields.Contains("username") && x.Customer.Username.StartsWith(term)) ||
5655
(fields.Contains("text") && x.Text.StartsWith(term)));
5756
}
5857
else
5958
{
6059
query = query.Where(x =>
6160
(fields.Contains("subject") && x.ForumTopic.Subject.Contains(term)) ||
61+
(fields.Contains("username") && x.Customer.Username.Contains(term)) ||
6262
(fields.Contains("text") && x.Text.Contains(term)));
6363
}
6464
}
@@ -100,7 +100,7 @@ protected virtual IQueryable<ForumTopic> GetForumTopicQuery(ForumSearchQuery sea
100100
}
101101
else if (filter.FieldName == "customerId")
102102
{
103-
query = query.Where(x => x.ForumTopic.CustomerId == (int)filter.Term);
103+
query = query.Where(x => x.CustomerId == (int)filter.Term);
104104
}
105105
else if (filter.FieldName == "createdon")
106106
{
@@ -141,6 +141,10 @@ orderby grp.Key
141141
{
142142
topicsQuery = OrderBy(ref ordered, topicsQuery, x => x.Subject, sort.Descending);
143143
}
144+
else if (sort.FieldName == "username")
145+
{
146+
topicsQuery = OrderBy(ref ordered, topicsQuery, x => x.Customer.Username, sort.Descending);
147+
}
144148
else if (sort.FieldName == "createdon")
145149
{
146150
topicsQuery = OrderBy(ref ordered, topicsQuery, x => x.CreatedOnUtc, sort.Descending);
@@ -149,10 +153,6 @@ orderby grp.Key
149153
{
150154
topicsQuery = OrderBy(ref ordered, topicsQuery, x => x.NumPosts, sort.Descending);
151155
}
152-
else if (sort.FieldName == "views")
153-
{
154-
topicsQuery = OrderBy(ref ordered, topicsQuery, x => x.Views, sort.Descending);
155-
}
156156
}
157157

158158
if (!ordered)

src/Presentation/SmartStore.Web/Administration/Controllers/SettingController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,8 @@ public ActionResult Search()
14421442

14431443
model.ForumSearchSettings.AvailableSearchFields = new List<SelectListItem>
14441444
{
1445-
new SelectListItem { Text = T("Forum.TopicTitle"), Value = "subject" }
1445+
new SelectListItem { Text = T("Forum.TopicTitle"), Value = "subject" },
1446+
new SelectListItem { Text = T("Admin.Customers.Customers.Fields.Username"), Value = "username" }
14461447
};
14471448

14481449
// Common facets.

0 commit comments

Comments
 (0)