Commit 2a75df04ea4a518615c2ed51894ecb1816ab75f6
1 parent
2b9a3d04
Exists in
master
and in
39 other branches
Using haystack to get related docs
Showing
2 changed files
with
9 additions
and
6 deletions
Show diff stats
src/super_archives/models.py
| ... | ... | @@ -12,6 +12,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch |
| 12 | 12 | from django.utils.translation import ugettext_lazy as _ |
| 13 | 13 | |
| 14 | 14 | from html2text import html2text |
| 15 | +from haystack.query import SearchQuerySet | |
| 15 | 16 | from taggit.managers import TaggableManager |
| 16 | 17 | |
| 17 | 18 | from .utils import blocks |
| ... | ... | @@ -157,6 +158,10 @@ class Thread(models.Model): |
| 157 | 158 | qs = qs.exclude(keyword__in=zip(*tags)[0]) |
| 158 | 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 | 165 | def save(self, *args, **kwargs): |
| 161 | 166 | super(Thread, self).save(*args, **kwargs) |
| 162 | 167 | self.update_keywords() | ... | ... |
src/super_archives/templates/message-thread.html
| ... | ... | @@ -165,16 +165,14 @@ |
| 165 | 165 | </li> |
| 166 | 166 | </ul> |
| 167 | 167 | |
| 168 | - {% if thread.tags.similar_objects %} | |
| 168 | + {% if thread.get_related %} | |
| 169 | 169 | <h4><strong>{% trans "Releated:" %}</strong></h4> |
| 170 | 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 | 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 | 175 | </li> |
| 177 | - {% endwith %} | |
| 178 | 176 | {% endfor %} |
| 179 | 177 | </ul> |
| 180 | 178 | {% endif %} | ... | ... |