mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 12:43:12 +08:00
This reverts commit f70caba3f20e4d224e6e86aad9b05b66375d8aa3.
This commit is contained in:
@ -1,8 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE "QuestionsQuestion" ADD COLUMN "contentSearch" TSVECTOR
|
|
||||||
GENERATED ALWAYS AS
|
|
||||||
to_tsvector('english', coalesce(content, ''))
|
|
||||||
STORED;
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE INDEX "QuestionsQuestion_contentSearch_idx" ON "QuestionsQuestion" USING GIN("textSearch");
|
|
@ -414,9 +414,6 @@ model QuestionsQuestion {
|
|||||||
answers QuestionsAnswer[]
|
answers QuestionsAnswer[]
|
||||||
QuestionsListQuestionEntry QuestionsListQuestionEntry[]
|
QuestionsListQuestionEntry QuestionsListQuestionEntry[]
|
||||||
|
|
||||||
contentSearch Unsupported("TSVECTOR")?
|
|
||||||
|
|
||||||
@@index([contentSearch])
|
|
||||||
@@index([lastSeenAt, id])
|
@@index([lastSeenAt, id])
|
||||||
@@index([upvotes, id])
|
@@index([upvotes, id])
|
||||||
}
|
}
|
||||||
|
@ -316,31 +316,6 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|||||||
return question;
|
return question;
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.query('getRelatedQuestionsByContent', {
|
|
||||||
input: z.object({
|
|
||||||
content: z.string(),
|
|
||||||
}),
|
|
||||||
async resolve({ ctx, input }) {
|
|
||||||
const escapeChars = /[()|&:*!]/g;
|
|
||||||
|
|
||||||
const query =
|
|
||||||
input.content
|
|
||||||
.replace(escapeChars, " ")
|
|
||||||
.trim()
|
|
||||||
.split(/\s+/)
|
|
||||||
.join(" | ");
|
|
||||||
|
|
||||||
const relatedQuestions = await ctx.prisma.$queryRaw`
|
|
||||||
SELECT * FROM "QuestionsQuestion"
|
|
||||||
WHERE
|
|
||||||
"contentSearch" @@ to_tsquery('english', ${query})
|
|
||||||
ORDER BY ts_rank("textSearch", to_tsquery('english', ${query})) DESC
|
|
||||||
`;
|
|
||||||
|
|
||||||
return relatedQuestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
.mutation('create', {
|
.mutation('create', {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
companyId: z.string(),
|
companyId: z.string(),
|
||||||
@ -562,7 +537,7 @@ export const questionsQuestionRouter = createProtectedRouter()
|
|||||||
|
|
||||||
const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
|
const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
|
||||||
|
|
||||||
const [ questionVote ] = await ctx.prisma.$transaction([
|
const [questionVote] = await ctx.prisma.$transaction([
|
||||||
ctx.prisma.questionsQuestionVote.delete({
|
ctx.prisma.questionsQuestionVote.delete({
|
||||||
where: {
|
where: {
|
||||||
id: input.id,
|
id: input.id,
|
||||||
|
Reference in New Issue
Block a user