[qeustions][chore] update text search

pull/412/head
hpkoh 2 years ago
parent 818ad26563
commit 2126cede0b

@ -319,8 +319,6 @@ export const questionsQuestionRouter = createProtectedRouter()
.query('getRelatedQuestionsByContent', { .query('getRelatedQuestionsByContent', {
input: z.object({ input: z.object({
content: z.string(), content: z.string(),
pageNum: z.number(),
pageSize: z.number(),
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
const escapeChars = /[()|&:*!]/g; const escapeChars = /[()|&:*!]/g;
@ -333,11 +331,10 @@ export const questionsQuestionRouter = createProtectedRouter()
.join(" | "); .join(" | ");
const relatedQuestions = await ctx.prisma.$queryRaw` const relatedQuestions = await ctx.prisma.$queryRaw`
SELECT content FROM "QuestionsQuestion" SELECT * FROM "QuestionsQuestion"
WHERE WHERE
"contentSearch" @@ to_tsquery('english', ${query}) "contentSearch" @@ to_tsquery('english', ${query})
ORDER BY ts_rank("textSearch", to_tsquery('english', ${query})) DESC ORDER BY ts_rank("textSearch", to_tsquery('english', ${query})) DESC
LIMIT 10;
`; `;
return relatedQuestions; return relatedQuestions;

Loading…
Cancel
Save