def show_saved_documents(request): """ Displays a list of all the documents that were marked as relevant by the user. """ # Timed out? if time_search_experiment_out(request): return redirect('timeout') ec = get_experiment_context(request) taskid = ec['taskid'] condition = ec['condition'] uname = ec['username'] current_search = request.session['queryurl'] user_judgement = -2 if request.method == 'GET': getdict = request.GET if 'judge' not in getdict and 'docid' not in getdict: # Log only if user is entering the page, not after clicking a relevant button logging.debug('LOG_VIEW_SAVED_DOCS') log_event(event="VIEW_SAVED_DOCS", request=request) if 'judge' in getdict: user_judgement = int(getdict['judge']) if 'docid' in getdict: docid = int(getdict['docid']) if (user_judgement > -2) and (docid > -1): # updates the judgement for this document doc_length = ixr.doc_field_length(docid, 'content') trecid = ixr.stored_fields(docid)['docid'] user_judgement = mark_document(request=request, whooshid=docid, trecid=trecid, judgement=user_judgement, doc_length=doc_length) # Get documents that are for this task, and for this user u = User.objects.get(username=uname) docs = DocumentsExamined.objects.filter(user=u).filter(task=taskid) context_dict = {'participant': uname, 'task': taskid, 'condition': condition, 'current_search': current_search, 'docs': docs} return render(request, 'trecdo/saved_documents.html', context_dict)
def show_document(request, whoosh_docid): # check for timeout """ Displays the document selected by the user :param request: :param whoosh_docid: the way of identifying the selected document :return: """ if time_search_experiment_out(request): return redirect('timeout') ec = get_experiment_context(request) uname = ec["username"] taskid = ec["taskid"] condition = ec["condition"] current_search = request.session['queryurl'] # get document from index fields = ixr.stored_fields(int(whoosh_docid)) title = fields["title"] content = fields["content"] doc_num = fields["docid"] doc_date = fields["timedate"] doc_source = fields["source"] doc_id = whoosh_docid # topic_num = ec["topicnum"] def get_document_rank(): """ Returns the rank (integer) for the given document ID. -1 is returned if the document is not found in the session ranked list. """ the_docid = int(whoosh_docid) ranked_results = request.session.get('results_ranked', []) # Some list comprehension - returns a list of one integer with the rank of a given document # if it exists in ranked_results; returns a blank list if the document is not present. at_rank = [item[1] for item in ranked_results if item[0] == the_docid] if len(at_rank) > 0: return at_rank[0] else: return -1 # check if there are any get parameters. user_judgement = -2 # rank = 0 if request.is_ajax(): getdict = request.GET if 'judge' in getdict: user_judgement = int(getdict['judge']) rank = get_document_rank() # marks that the document has been marked rel or nonrel doc_length = ixr.doc_field_length(long(request.GET.get('docid', 0)), 'content') user_judgement = mark_document(request, doc_id, user_judgement, title, doc_num, rank, doc_length) # mark_document handles logging of this event return JsonResponse(user_judgement, safe=False) else: log_event(event="DOC_CLICKED", request=request, whooshid=whoosh_docid) # marks that the document has been viewed rank = get_document_rank() doc_length = ixr.doc_field_length(long(doc_id), 'content') user_judgement = mark_document(request, doc_id, user_judgement, title, doc_num, rank, doc_length) context_dict = {'participant': uname, 'task': taskid, 'condition': condition, 'current_search': current_search, 'docid': doc_id, 'docnum': doc_num, 'title': title, 'doc_date': doc_date, 'doc_source': doc_source, 'content': content, 'user_judgement': user_judgement, 'rank': rank} if request.GET.get('backtoassessment', False): context_dict['backtoassessment'] = True return render(request, 'trecdo/document.html', context_dict)