Skip to content

Commit

Permalink
add simple search for publications by their title, orders them by non…
Browse files Browse the repository at this point in the history
…-obsoleted first and then most recent first (also adds a small ellipsis indicator that more results exist) (#1965)
  • Loading branch information
Masterjun3 authored Aug 24, 2024
1 parent 2c9b8ff commit 3c910d7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
29 changes: 29 additions & 0 deletions TASVideos/Pages/Search/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@
</div>
</fullrow>

<div condition="Model.PublicationResults.Any()">
<h4>Publication Results:</h4>
<standard-table>
<table-head columns="Publication"></table-head>
@foreach (var result in Model.PublicationResults.Take(IndexModel.PageSize))
{
<tr style="@(result.IsObsolete ? "opacity: 0.6" : "")">
<td><pub-link id="result.Id">[@result.Id] @result.Title</pub-link></td>
</tr>
}
@if (Model.PublicationResults.Count == IndexModel.PageSize + 1)
{
<tr><td>...</td></tr>
}
</standard-table>
</div>

<div condition="Model.GameResults.Any()">
<h4>Game Results:</h4>
<standard-table>
Expand All @@ -56,6 +73,10 @@
</td>
</tr>
}
@if (Model.GameResults.Count == IndexModel.PageSize + 1)
{
<tr><td>...</td><td></td><td></td></tr>
}
</standard-table>
</div>

Expand All @@ -74,6 +95,10 @@
</td>
</tr>
}
@if (Model.PageResults.Count == IndexModel.PageSize + 1)
{
<tr><td>...</td><td></td></tr>
}
</standard-table>
</div>

Expand All @@ -92,6 +117,10 @@
</td>
</tr>
}
@if (Model.PostResults.Count == IndexModel.PageSize + 1)
{
<tr><td>...</td><td></td></tr>
}
</standard-table>
</div>

Expand Down
14 changes: 14 additions & 0 deletions TASVideos/Pages/Search/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class IndexModel(ApplicationDbContext db) : BasePageModel
public List<PageSearch> PageResults { get; set; } = [];
public List<PostSearch> PostResults { get; set; } = [];
public List<GameSearch> GameResults { get; set; } = [];
public List<PublicationSearch> PublicationResults { get; set; } = [];

public async Task<IActionResult> OnGet()
{
Expand Down Expand Up @@ -71,6 +72,18 @@ public async Task<IActionResult> OnGet()
g.GameVersions.Select(v => v.System!.Code),
g.GameGroups.Select(gg => new GameGroupEntry(gg.GameGroupId, gg.GameGroup!.Name))))
.ToListAsync();

PublicationResults = await db.Publications
.Where(p => EF.Functions.ToTsVector("simple", p.Title).Matches(EF.Functions.WebSearchToTsQuery("simple", SearchTerms)))
.OrderBy(p => p.ObsoletedById == null ? 0 : 1)
.ThenByDescending(p => p.CreateTimestamp)
.Skip(skip)
.Take(PageSize + 1)
.Select(p => new PublicationSearch(
p.Id,
p.Title,
p.ObsoletedById != null))
.ToListAsync();
}

return Page();
Expand All @@ -80,4 +93,5 @@ public record PageSearch(string Highlight, string PageName);
public record PostSearch(string Highlight, string TopicName, int PostId);
public record GameSearch(int Id, string DisplayName, IEnumerable<string> Systems, IEnumerable<GameGroupEntry> Groups);
public record GameGroupEntry(int Id, string Name);
public record PublicationSearch(int Id, string Title, bool IsObsolete);
}

0 comments on commit 3c910d7

Please sign in to comment.