# -*- coding:utf8 -*-
# Copyright (C) 2013 FinalsClub Foundation
+import traceback
from django.core.management.base import BaseCommand
from karmaworld.apps.notes.models import Note
from karmaworld.apps.notes.search import *
try:
print "Indexing {n}".format(n=note)
add_document(note)
- except:
+ except Exception, e:
+ traceback.print_exc()
continue
"""Returns note IDs matching the given query,
filtered by course ID if given"""
if course_id:
- results = index.search('(text:"%s" OR name:"%s") AND course_id:%s' % (query, query, course_id))
+ real_query = '("%s" OR name:"%s") AND course_id:%s' % (query, query, course_id)
else:
- results = index.search('text:"%s" OR name:"%s"' % (query, query))
+ real_query = '"%s" OR name:"%s"' % (query, query)
- matching_note_ids = [r['docid'] for r in results['results']]
+ raw_results = index.search(real_query, snippet_fields=['text'])
- return matching_note_ids
\ No newline at end of file
+ results = {r['docid']: r['snippet_text'] for r in raw_results['results']}
+
+ return results
\ No newline at end of file
return Note.objects.none()
if 'course_id' in self.request.GET:
- matching_note_ids = search.search(self.request.GET['query'],
+ matching_notes = search.search(self.request.GET['query'],
self.request.GET['course_id'])
else:
- matching_note_ids = search.search(self.request.GET['query'])
+ matching_notes = search.search(self.request.GET['query'])
- return Note.objects.filter(id__in=matching_note_ids)
+ instances = Note.objects.filter(id__in=matching_notes.viewkeys())
+ results = []
+ for i in instances:
+ results.append((i, matching_notes[str(i.id)]))
+
+ return results
def get_context_data(self, **kwargs):
if 'query' in self.request.GET:
padding-bottom: 20px;
margin-bottom: 20px;
}
+
+#no_results
+{
+ font-family: "MuseoSlab-900";
+ font-size: 10px;
+ color: #8e8e8e;
+ margin-bottom: 20px;
+}
\ No newline at end of file
<header id="global_header">
<div class="row">
- <div id="logo_container" class="small-6 large-3 columns">
- <a href="/">
- <img src="{{ STATIC_URL }}img/global_header_logo.png" alt="global_header_logo" width="144" height="17" />
- </a>
- </div><!--/logo container-->
-
- <div class="small-4 columns show-for-medium-up">
- {% if course.id %}
- <div id="search_container">
- <form action="{% url 'note_search' %}" method="GET">
- <input type="text" id="search_txt" name="query" placeholder="Search in this course">
- <input type="hidden" name="course_id" value="{{ course.id }}">
- </form>
+ <div id="logo_container" class="small-5 columns">
+ <div class="row">
+ <div class="small-5 columns">
+ <a href="/">
+ <img src="{{ STATIC_URL }}img/global_header_logo.png" alt="global_header_logo" width="144" height="17" />
+ </a>
</div>
- {% endif %}
- </div>
+ <div class="small-7 columns">
+ {% if course.id %}
+ <div id="search_container">
+ <form action="{% url 'note_search' %}" method="GET">
+ <input type="text" id="search_txt" name="query" placeholder="Search in this course">
+ <input type="hidden" name="course_id" value="{{ course.id }}">
+ </form>
+ </div>
+ {% endif %}
+ </div>
+ </div>
+ </div><!--/logo container-->
{% if display_add_course %}
<div class="small-2 columns small-offset-3 show-for-medium-up">
</div>
{% endif %}
+ <div id="login_container" class="small-1 columns">
+ <a class=white href="{% url 'about' %}">About</a>
+ </div>
+
</div>
</header><!--/global header-->
<div class="note_preview">
- {{ note.text|slice:":500" }} …
+ {% if note_preview %}
+ {{ note_preview|safe }} …
+ {% else %}
+ {{ note.text|slice:":500" }} …
+ {% endif %}
</div>
<section id="results_content">
<div id="results_header" class="hero_gradient_bar">
+
+ <div class="row">
+ <div class="twelve columns header_subhead">
+ <a href="{{ course.get_absolute_url}}">
+ <i class="fa fa-arrow-left"></i> back to {{ course.name }}
+ </a>
+ </div>
+ </div>
+
<div class="row">
<div class="small-12 columns header_subhead">
YOU SEARCHED FOR
<div id="results_container">
<div class="row">
- <div class="small-12 columns large-10 large-offset-1">
- {% for note in object_list %}
- {% include 'notes/note_list_entry.html' with note=note %}
- {% endfor %}
- </div>
+ {% if object_list %}
+ <div class="small-12 columns large-10 large-offset-1">
+ {% for tuple in object_list %}
+ {% include 'notes/note_list_entry.html' with note=tuple.0 note_preview=tuple.1 %}
+ {% endfor %}
+ </div>
+ {% else %}
+ <div id="no_results" class="small-12 columns center column">
+ <h4>Sorry! No results were found.</h4>
+ </div>
+ {% endif %}
</div>
</div><!-- /course_container -->