|
12 | 12 | from website.models import Question, Answer, Notification, AnswerComment |
13 | 13 | from spoken_auth.models import TutorialDetails, TutorialResources |
14 | 14 | from website.forms import NewQuestionForm, AnswerQuesitionForm |
15 | | -from website.helpers import get_video_info, prettify |
| 15 | +from website.helpers import get_video_info, prettify, clean_user_data, get_similar_questions |
16 | 16 | from django.conf import settings |
17 | 17 | from website.templatetags.permission_tags import can_edit |
18 | 18 | from spoken_auth.models import FossCategory |
@@ -546,15 +546,22 @@ def ajax_answer_comment_update(request): |
546 | 546 |
|
547 | 547 | def ajax_similar_questions(request): |
548 | 548 | if request.method == 'POST': |
549 | | - category = request.POST['category'] |
550 | | - tutorial = request.POST['tutorial'] |
551 | | - # minute_range = request.POST['minute_range'] |
552 | | - # second_range = request.POST['second_range'] |
553 | | - |
554 | | - # add more filtering when the forum grows |
555 | | - questions = Question.objects.filter(category=category).filter(tutorial=tutorial) |
| 549 | + category = request.POST['category'].replace(' ','-') |
| 550 | + tutorial = request.POST['tutorial'].replace(' ','-') |
| 551 | + title = request.POST['title'] |
| 552 | + user_title = clean_user_data(title) |
| 553 | + # Increase the threshold as the Forums questions increase |
| 554 | + THRESHOLD = 0.3 |
| 555 | + top_ques = [] |
| 556 | + questions = Question.objects.filter(category=category,tutorial=tutorial) |
| 557 | + for question in questions: |
| 558 | + question.similarity= get_similar_questions(user_title,question.title) |
| 559 | + if question.similarity >= THRESHOLD: |
| 560 | + top_ques.append(question) |
| 561 | + top_ques = sorted(top_ques,key=lambda x : x.similarity, reverse=True) |
556 | 562 | context = { |
557 | | - 'questions': questions |
| 563 | + 'questions': top_ques, |
| 564 | + 'questions_count':len(top_ques) |
558 | 565 | } |
559 | 566 | return render(request, 'website/templates/ajax-similar-questions.html', context) |
560 | 567 |
|
|
0 commit comments