Commit 2a75df04ea4a518615c2ed51894ecb1816ab75f6

Authored by Sergio Oliveira
1 parent 2b9a3d04

Using haystack to get related docs

src/super_archives/models.py
@@ -12,6 +12,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch @@ -12,6 +12,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch
12 from django.utils.translation import ugettext_lazy as _ 12 from django.utils.translation import ugettext_lazy as _
13 13
14 from html2text import html2text 14 from html2text import html2text
  15 +from haystack.query import SearchQuerySet
15 from taggit.managers import TaggableManager 16 from taggit.managers import TaggableManager
16 17
17 from .utils import blocks 18 from .utils import blocks
@@ -157,6 +158,10 @@ class Thread(models.Model): @@ -157,6 +158,10 @@ class Thread(models.Model):
157 qs = qs.exclude(keyword__in=zip(*tags)[0]) 158 qs = qs.exclude(keyword__in=zip(*tags)[0])
158 qs.delete() 159 qs.delete()
159 160
  161 + def get_related(self):
  162 + query_string = u' '.join(self.tags.names())
  163 + return SearchQuerySet().filter(text=query_string)
  164 +
160 def save(self, *args, **kwargs): 165 def save(self, *args, **kwargs):
161 super(Thread, self).save(*args, **kwargs) 166 super(Thread, self).save(*args, **kwargs)
162 self.update_keywords() 167 self.update_keywords()
src/super_archives/templates/message-thread.html
@@ -165,16 +165,14 @@ @@ -165,16 +165,14 @@
165 </li> 165 </li>
166 </ul> 166 </ul>
167 167
168 - {% if thread.tags.similar_objects %} 168 + {% if thread.get_related %}
169 <h4><strong>{% trans "Releated:" %}</strong></h4> 169 <h4><strong>{% trans "Releated:" %}</strong></h4>
170 <ul class="unstyled-list"> 170 <ul class="unstyled-list">
171 - {% for similar in thread.tags.similar_objects|slice:":10" %}  
172 - {% with similar.message_set.first as message %} 171 + {% for similar in thread.get_related|slice:":10" %}
173 <li> 172 <li>
174 - <span class="label label-primary label-small">{{ similar.mailinglist.name }}</span>  
175 - <a href="{% url 'thread_view' similar.mailinglist.name similar.subject_token %}">{{ message.subject_clean|truncatechars:50 }}</a> 173 + <span class="label label-primary label-small">{{ similar.tag }}</span>
  174 + <a href="{{ similar.url }}">{{ similar.title|truncatechars:50 }}</a>
176 </li> 175 </li>
177 - {% endwith %}  
178 {% endfor %} 176 {% endfor %}
179 </ul> 177 </ul>
180 {% endif %} 178 {% endif %}