Skip to content

Commit e6e714f

Browse files
dahliaampagent
andcommitted
Fix search functionality: search content and exclude shared posts
- Fix search not returning results by querying content_html instead of content - Filter out shared posts from search results to show only original posts and replies - Use isNull() for proper NULL value comparison in Drizzle ORM Amp-Thread-ID: https://ampcode.com/threads/T-a8878c55-9f2e-4967-a456-399ff78ba98a Co-authored-by: Amp <amp@ampcode.com>
1 parent 0e35f18 commit e6e714f

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Version 0.6.16
66

77
To be released.
88

9+
- Fixed search functionality not returning any results when searching for
10+
post content.
11+
12+
- Fixed search results including shared posts (reposts/reblogs). Search now
13+
shows only original posts and replies, excluding shares.
14+
915

1016
Version 0.6.15
1117
--------------

src/api/v2/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ import {
77
} from "@fedify/fedify";
88
import { zValidator } from "@hono/zod-validator";
99
import { getLogger } from "@logtape/logtape";
10-
import { and, desc, eq, ilike, inArray, lte, or, sql } from "drizzle-orm";
10+
import {
11+
and,
12+
desc,
13+
eq,
14+
ilike,
15+
inArray,
16+
isNull,
17+
lte,
18+
or,
19+
sql,
20+
} from "drizzle-orm";
1121
import { Hono } from "hono";
1222
import { z } from "zod";
1323
import { db } from "../../db";
@@ -79,6 +89,7 @@ app.get(
7989
? await db.query.posts.findMany({
8090
where: and(
8191
or(eq(posts.iri, q), eq(posts.url, q)),
92+
isNull(posts.sharingId),
8293
lte(posts.published, sql`NOW() + INTERVAL '5 minutes'`),
8394
),
8495
with: getPostRelations(owner.id),
@@ -135,7 +146,10 @@ app.get(
135146
}
136147
}
137148
if (query.type == null || query.type === "statuses") {
138-
let filter = ilike(posts.content, `%${q}%`);
149+
let filter = and(
150+
ilike(posts.contentHtml, `%${q}%`),
151+
isNull(posts.sharingId),
152+
)!;
139153
if (query.account_id != null) {
140154
filter = and(filter, eq(posts.accountId, query.account_id))!;
141155
}

0 commit comments

Comments
 (0)