[questions][fix] fix similar questions

pull/468/head
Jeff Sieu 3 years ago
parent c52f24ecc9
commit 38a4bdf06c

@ -1,8 +1,8 @@
-- AlterTable
ALTER TABLE "QuestionsQuestion" ADD COLUMN "contentSearch" TSVECTOR
GENERATED ALWAYS AS
to_tsvector('english', coalesce(content, ''))
(to_tsvector('english', coalesce(content, '')))
STORED;
-- CreateIndex
CREATE INDEX "QuestionsQuestion_contentSearch_idx" ON "QuestionsQuestion" USING GIN("textSearch");
CREATE INDEX "QuestionsQuestion_contentSearch_idx" ON "QuestionsQuestion" USING GIN("contentSearch");

@ -157,7 +157,7 @@ export default function BaseQuestionCard({
onUpvote={handleUpvote}
/>
)}
<div className="flex flex-col items-start gap-2">
<div className="flex flex-1 flex-col items-start gap-2">
<div className="flex items-baseline justify-between self-stretch">
<div className="flex items-center gap-2 text-slate-500">
{showAggregateStatistics && (

@ -200,10 +200,13 @@ export default function ContributeQuestionForm({
{similarQuestions?.map((question) => (
<SimilarQuestionCard
key={question.id}
content="Given an array of integers nums and an integer target, return indices of the two numbers such that they add up. Given an array of integers nums and an integer target, return indices"
content={question.content}
questionId={question.id}
timestamp="Today"
type="CODING"
timestamp={question.lastSeenAt.toLocaleDateString(undefined, {
month: 'short',
year: 'numeric',
})}
type={question.questionType}
onSimilarQuestionClick={() => {
// eslint-disable-next-line no-console
console.log('hi!');

@ -209,17 +209,13 @@ export const questionsQuestionRouter = createProtectedRouter()
.join(' | ');
const relatedQuestions = (await ctx.prisma.$queryRaw`
SELECT * FROM "QuestionsQuestion"
WHERE "contentSearch" @@ to_tsquery(${query})
ORDER BY ts_rank("contentSearch", to_tsquery(${query})) DESC
SELECT "id", "userId", "content", "createdAt", "updatedAt", "questionType", "lastSeenAt", "upvotes" FROM "QuestionsQuestion"
WHERE
"contentSearch" @@ to_tsquery('english', ${query})
ORDER BY ts_rank("contentSearch", to_tsquery('english', ${query})) DESC
`) as Array<QuestionsQuestion>;
// Dummy data to make this return something
return await ctx.prisma.questionsQuestion.findMany({
take: 5,
});
// Return relatedQuestions;
return relatedQuestions;
},
})
.mutation('create', {

Loading…
Cancel
Save