amitsolanki24_'s avatar

Get related questions from DB

Hello everyone,

I'm facing a problem how can I get all the similar or related questions from db.

$question = "What is HTML?";
$results = DB::table('questions')
    ->select('question')
    ->whereRaw(
        "MATCH(question) AGAINST(? IN NATURAL LANGUAGE MODE)",
        [$question]
    )
    ->get();

foreach ($results as $result) {
    echo $result->question;
}

I tried this code, but I want to go over every question—not just the one that was provided.

0 likes
6 replies
Snapey's avatar

exclude the question with whereNot, otherwise the question will always be an exact match for what you are looking for.

Depending on the number of questions, I would probably look for a solution using AI

1 like
amitsolanki24_'s avatar

@Snapey exclude the question with whereNot,

But I dont know which questions to use in WhereNot. Because I'm not sure which questions are duplicates in the entire questions table. If I would manually find out duplicate questions then it takes lot of time.

amitsolanki24_'s avatar

@Snapey oh I didn't get notification, I'm trying to find matches with full question text instead of question id because my question id is integer.

Please or to participate in this conversation.