|
|
@ -291,14 +291,20 @@ export const questionsQuestionRouter = createRouter()
|
|
|
|
.split(/\s+/)
|
|
|
|
.split(/\s+/)
|
|
|
|
.join(' | ');
|
|
|
|
.join(' | ');
|
|
|
|
|
|
|
|
|
|
|
|
const relatedQuestionsId: Array<{ id: string }> = await ctx.prisma
|
|
|
|
let relatedQuestionsId: Array<{ id: string }> = [];
|
|
|
|
.$queryRaw`
|
|
|
|
|
|
|
|
SELECT id FROM "QuestionsQuestion"
|
|
|
|
if (input.content !== "") {
|
|
|
|
WHERE
|
|
|
|
relatedQuestionsId = await ctx.prisma
|
|
|
|
to_tsvector("content") @@ to_tsquery('english', ${query})
|
|
|
|
.$queryRaw`
|
|
|
|
AND ts_rank_cd(to_tsvector("content"), to_tsquery('english', ${query}), 32) > 0.8
|
|
|
|
SELECT id FROM "QuestionsQuestion"
|
|
|
|
ORDER BY ts_rank_cd(to_tsvector("content"), to_tsquery('english', ${query}), 32) DESC;
|
|
|
|
WHERE
|
|
|
|
`;
|
|
|
|
to_tsvector("content") @@ to_tsquery('english', ${query})
|
|
|
|
|
|
|
|
AND ts_rank_cd(to_tsvector("content"), to_tsquery('english', ${query}), 32) > 0.8
|
|
|
|
|
|
|
|
ORDER BY ts_rank_cd(to_tsvector("content"), to_tsquery('english', ${query}), 32) DESC;
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const relatedQuestionsIdArray = relatedQuestionsId.map(
|
|
|
|
const relatedQuestionsIdArray = relatedQuestionsId.map(
|
|
|
|
(current) => current.id,
|
|
|
|
(current) => current.id,
|
|
|
@ -354,9 +360,9 @@ export const questionsQuestionRouter = createRouter()
|
|
|
|
orderBy: sortCondition,
|
|
|
|
orderBy: sortCondition,
|
|
|
|
take: input.limit + 1,
|
|
|
|
take: input.limit + 1,
|
|
|
|
where: {
|
|
|
|
where: {
|
|
|
|
id: {
|
|
|
|
id: input.content !== "" ? {
|
|
|
|
in: relatedQuestionsIdArray,
|
|
|
|
in: relatedQuestionsIdArray,
|
|
|
|
},
|
|
|
|
} : undefined,
|
|
|
|
...(input.questionTypes.length > 0
|
|
|
|
...(input.questionTypes.length > 0
|
|
|
|
? {
|
|
|
|
? {
|
|
|
|
questionType: {
|
|
|
|
questionType: {
|
|
|
|