[questions][chore] update naming

This commit is contained in:
hpkoh
2022-10-23 18:42:28 +08:00
parent 3d70ca3b87
commit fdbc04a475
2 changed files with 7 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
-- AlterTable
ALTER TABLE "QuestionsQuestion" ADD COLUMN "contentSearch" TSVECTOR
ALTER TABLE "QuestionsQuestion" ADD COLUMN "contentSearch" TSVECTOR
GENERATED ALWAYS AS
to_tsvector('english', coalesce(content, ''))
STORED;

View File

@@ -224,14 +224,17 @@ export const questionsQuestionRouter = createProtectedRouter()
.split(/\s+/)
.join(" | ");
const res = await ctx.prisma.$queryRaw`
SELECT content FROM "Post"
const relatedQuestions = await ctx.prisma.$queryRaw`
SELECT content FROM "QuestionsQuestion"
WHERE
"contentSearch" @@ to_tsquery('english', ${query})
ORDER BY ts_rank("textSearch", to_tsquery('english', ${query})) DESC
LIMIT 10;
`;
return relatedQuestions;
}
})
.mutation('create', {
input: z.object({
@@ -454,7 +457,7 @@ export const questionsQuestionRouter = createProtectedRouter()
const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
const [questionVote] = await ctx.prisma.$transaction([
const [ questionVote ] = await ctx.prisma.$transaction([
ctx.prisma.questionsQuestionVote.delete({
where: {
id: input.id,