summaryrefslogtreecommitdiffstats
path: root/forum
diff options
context:
space:
mode:
Diffstat (limited to 'forum')
-rw-r--r--forum/models.py11
-rw-r--r--forum/templatetags/extra_tags.py4
-rw-r--r--forum/views.py12
3 files changed, 22 insertions, 5 deletions
diff --git a/forum/models.py b/forum/models.py
index 39058bea..60fcee0a 100644
--- a/forum/models.py
+++ b/forum/models.py
@@ -14,6 +14,10 @@ from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
import django.dispatch
import settings
+import logging
+
+if settings.USE_SPHINX_SEARCH == True:
+ from djangosphinx.models import SphinxSearch
from forum.managers import *
from const import *
@@ -184,6 +188,13 @@ class Question(models.Model):
votes = generic.GenericRelation(Vote)
flagged_items = generic.GenericRelation(FlaggedItem)
+ if settings.USE_SPHINX_SEARCH == True:
+ search = SphinxSearch(
+ index=' '.join(settings.SPHINX_SEARCH_INDICES),
+ mode='SPH_MATCH_ALL',
+ )
+ logging.debug('have sphinx search')
+
objects = QuestionManager()
def save(self, **kwargs):
diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py
index 8bd0e128..96dc9024 100644
--- a/forum/templatetags/extra_tags.py
+++ b/forum/templatetags/extra_tags.py
@@ -332,8 +332,8 @@ class BlockResourceNode(template.Node):
for item in self.items:
bit = item.render(context)
out += bit
- out = out.replace(' ','')
- return os.path.normpath(out) + '?v=%d' % settings.RESOURCE_REVISION
+ out = os.path.normpath(out) + '?v=%d' % settings.RESOURCE_REVISION
+ return out.replace(' ','')
@register.tag(name='blockresource')
def blockresource(parser,token):
diff --git a/forum/views.py b/forum/views.py
index e4ccaa16..8f7d07fd 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -2193,10 +2193,16 @@ def search(request):
view_id = "latest"
orderby = "-added_at"
- objects = Question.objects.filter(deleted=False).extra(where=['title like %s'], params=['%' + keywords + '%']).order_by(orderby)
+ if settings.USE_SPHINX_SEARCH == True:
+ #search index is now free of delete questions and answers
+ #so there is not "antideleted" filtering here
+ objects = Question.search.query(keywords)
+ #no related selection either because we're relying on full text search here
+ else:
+ objects = Question.objects.filter(deleted=False).extra(where=['title like %s'], params=['%' + keywords + '%']).order_by(orderby)
+ # RISK - inner join queries
+ objects = objects.select_related();
- # RISK - inner join queries
- objects = objects.select_related();
objects_list = Paginator(objects, pagesize)
questions = objects_list.page(page)