Revert "[questions][feat] add text search (#412)" (#428)

This reverts commit f70caba3f2.
pull/433/head
hpkoh 2 years ago committed by GitHub
parent 3b4cba3771
commit 79b62234ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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[]
QuestionsListQuestionEntry QuestionsListQuestionEntry[]
contentSearch Unsupported("TSVECTOR")?
@@index([contentSearch])
@@index([lastSeenAt, id])
@@index([upvotes, id])
}

@ -316,31 +316,6 @@ export const questionsQuestionRouter = createProtectedRouter()
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', {
input: z.object({
companyId: z.string(),
@ -562,7 +537,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,

Loading…
Cancel
Save