Skip to content

Commit

Permalink
add fulltext index to blockText
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowySailor committed Apr 17, 2024
1 parent 9b06d53 commit 66c6f07
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/api/search/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ export async function GET(request: NextRequest) {
INNER JOIN "Volume" ON "Volume".id = "Page"."volumeId"
INNER JOIN "Series" ON "Series".id = "Volume"."seriesId"
CROSS JOIN LATERAL unnest("blockText") WITH ORDINALITY AS t(text_element, idx)
WHERE t.text_element LIKE $1 ${nsfwFilter}
WHERE
"Page"."blockText" &@ $1
AND
t.text_element &@ $1
${nsfwFilter}
ORDER BY "isReading" DESC, "Page"."volumeId", number ASC
LIMIT 20
OFFSET $3
`;

const pages: SearchResult[] = await prisma.$queryRawUnsafe(
rawQuery,
`%${q}%`,
q,
session.user.userId,
offset,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- CreateIndex
CREATE INDEX pgroonga_blocks_index ON public."Page" USING pgroonga ("blockText");
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ model Page {
volume Volume @relation(fields: [volumeId], references: [id])
@@unique([number, volumeId], name: "volumeNum")
@@index([blockText], map: "pgroonga_blocks_index")
}

model Reading {
Expand Down

0 comments on commit 66c6f07

Please sign in to comment.