Skip to content

Commit 2d9caeb

Browse files
committed
fix: improve counting.
1 parent dc59e7a commit 2d9caeb

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

PinkSea.Frontend/src/views/SearchView.vue

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,44 @@ const loadMore = async () => {
6464
6565
applyNew(data);
6666
};
67+
68+
const setTab = (tab: SearchType) => {
69+
currentTab.value = tab;
70+
71+
if (currentTab.value == SearchType.Tags) {
72+
tags.value = [];
73+
} else if (currentTab.value == SearchType.Profiles) {
74+
profiles.value = [];
75+
}
76+
};
6777
</script>
6878

6979
<template>
7080
<PanelLayout>
7181
<div id="tabs">
72-
<a v-for="tab in tabs" :class="tab.id == currentTab ? 'selected' : ''" v-on:click.prevent="currentTab = tab.id" v-bind:key="tab.id">{{ $t(tab.i18n) }}</a>
82+
<a v-for="tab in tabs" :class="tab.id == currentTab ? 'selected' : ''" v-on:click.prevent="setTab(tab.id)"
83+
v-bind:key="tab.id">{{ $t(tab.i18n) }}</a>
7384
</div>
7485
<div v-if="currentTab == SearchType.Posts">
75-
<TimeLine endpoint="com.shinolabs.pinksea.getSearchResults" :xrpc-params="{ query: $route.params.value, type: SearchType.Posts }" />
86+
<TimeLine endpoint="com.shinolabs.pinksea.getSearchResults"
87+
:xrpc-params="{ query: $route.params.value, type: SearchType.Posts }" />
7688
</div>
7789
<div v-else-if="currentTab == SearchType.Tags" class="search-result-list">
78-
<div v-for="tag of tags" :key="tag.tag">
90+
<div v-if="tags.length > 0" v-for="tag of tags" :key="tag.tag">
7991
<SearchTag :tag="tag" v-on:click.prevent="open(tag.tag)" />
8092
</div>
93+
<div v-else class="search-centered">
94+
{{ $t("timeline.nothing_here") }}
95+
</div>
8196
<Intersector @intersected="loadMore" />
8297
</div>
8398
<div v-else-if="currentTab == SearchType.Profiles" class="search-result-list">
84-
<div v-for="profile of profiles" :key="profile.did">
99+
<div v-if="profiles.length > 0" v-for="profile of profiles" :key="profile.did">
85100
<SearchProfileCard :profile="profile" v-on:click.prevent="open(profile.did)" />
86101
</div>
102+
<div v-else class="search-centered">
103+
{{ $t("timeline.nothing_here") }}
104+
</div>
87105
<Intersector @intersected="loadMore" />
88106
</div>
89107
</PanelLayout>
@@ -112,7 +130,8 @@ const loadMore = async () => {
112130
}
113131
114132
#tabs a.selected {
115-
background: #ffb6c1; color: #263b48;
133+
background: #ffb6c1;
134+
color: #263b48;
116135
font-weight: bold;
117136
}
118137
@@ -124,7 +143,11 @@ const loadMore = async () => {
124143
padding: 10px;
125144
}
126145
127-
.search-result-list > div {
146+
.search-result-list>div {
128147
cursor: pointer;
129148
}
149+
150+
.search-centered {
151+
text-align: center;
152+
}
130153
</style>

PinkSea/Services/SearchService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ public class SearchService(
1616
{
1717
public async Task<List<OekakiModel>> SearchPosts(string query, int limit, DateTimeOffset since)
1818
{
19+
var lowerQuery = query.ToLower();
1920
var list = await dbContext.Oekaki
2021
.Include(o => o.TagOekakiRelations)
2122
.Include(o => o.Author)
22-
.Where(o => !o.Tombstone)
23-
.Where(o => o.AltText!.ToLower().Contains(query.ToLower()) ||
24-
o.TagOekakiRelations!.Any(to => to.TagId.ToLower().Contains(query.ToLower()))) // TODO: Author
23+
.Where(o => !o.Tombstone && o.ParentId == null)
24+
.Where(o => o.AltText!.ToLower().Contains(lowerQuery) ||
25+
o.TagOekakiRelations!.Any(to => to.TagId.ToLower().Contains(lowerQuery)) ||
26+
o.Author.Handle!.ToLower().Contains(lowerQuery))
2527
.Distinct()
2628
.OrderByDescending(o => o.IndexedAt)
2729
.Where(o => o.IndexedAt < since)
@@ -37,14 +39,14 @@ public async Task<List<TagSearchResult>> SearchTags(string query, int limit, Dat
3739
.Where(t => t.Name.ToLower().Contains(query.ToLower()))
3840
.Join(dbContext.TagOekakiRelations, t => t.Name, to => to.TagId, (t, to) => new { t, to })
3941
.Join(dbContext.Oekaki, c => c.to.OekakiId, o => o.Key, (c, o) => new { c.t, c.to, o })
40-
.Distinct()
42+
.Where(c => !c.o.Tombstone && c.o.ParentId == null)
4143
.GroupBy(c => c.t.Name)
4244
.Take(limit)
4345
.Select(c => new
4446
{
4547
Tag = c.Key,
4648
Oekaki = c.First().o,
47-
Count = c.Count()
49+
Count = c.Select(p => p.o.Key).Distinct().Count()
4850
})
4951
.ToListAsync();
5052

0 commit comments

Comments
 (0)