summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2015-06-06 14:16:19 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2015-06-06 14:16:19 (GMT)
commit3c5644e76879aa9a9529510d9567d3e997684bad (patch)
tree4c2b17a876919c7850da5dfa781af5873bc48c01
parent81f8a9a089e54e65321c46a702025e81ffbf67f2 (diff)
downloadcombo-3c5644e76879aa9a9529510d9567d3e997684bad.zip
combo-3c5644e76879aa9a9529510d9567d3e997684bad.tar.gz
combo-3c5644e76879aa9a9529510d9567d3e997684bad.tar.bz2
add indexing of pages (#6793)
-rw-r--r--combo/data/models.py11
-rw-r--r--combo/data/search_indexes.py31
-rw-r--r--combo/data/templates/combo/search/page.txt5
-rw-r--r--combo/settings.py8
4 files changed, 54 insertions, 1 deletions
diff --git a/combo/data/models.py b/combo/data/models.py
index 241772f..3ebb574 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -25,6 +25,7 @@ from django.db import models
from django.db.models import Max
from django.forms import models as model_forms
from django import template
+from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
@@ -160,8 +161,11 @@ class Page(models.Model):
def is_visible(self, user=None):
return element_is_visible(self, user=user)
+ def get_cells(self):
+ return CellBase.get_cells(page_id=self.id)
+
def get_serialized_page(self):
- cells = CellBase.get_cells(page_id=self.id)
+ cells = self.get_cells()
serialized_page = json.loads(serializers.serialize('json', [self]))[0]
del serialized_page['pk']
del serialized_page['model']
@@ -342,6 +346,11 @@ class CellBase(models.Model):
tmpl = template.loader.get_template(self.template_name)
return tmpl.render(context)
+ def render_for_search(self):
+ from django.template import Context
+ from HTMLParser import HTMLParser
+ return HTMLParser().unescape(strip_tags(self.render(Context())))
+
@register_cell_class
class TextCell(CellBase):
diff --git a/combo/data/search_indexes.py b/combo/data/search_indexes.py
new file mode 100644
index 0000000..43ad9af
--- /dev/null
+++ b/combo/data/search_indexes.py
@@ -0,0 +1,31 @@
+# combo - content management system
+# Copyright (C) 2014-2015 Entr'ouvert
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from haystack import indexes
+
+from .models import Page, CellBase
+
+class PageIndex(indexes.SearchIndex, indexes.Indexable):
+ title = indexes.CharField(model_attr='title', boost=1.5)
+ text = indexes.CharField(document=True, use_template=True,
+ template_name='combo/search/page.txt')
+ url = indexes.CharField(indexed=False)
+
+ def get_model(self):
+ return Page
+
+ def prepare_url(self, obj):
+ return obj.get_online_url()
diff --git a/combo/data/templates/combo/search/page.txt b/combo/data/templates/combo/search/page.txt
new file mode 100644
index 0000000..9d03682
--- /dev/null
+++ b/combo/data/templates/combo/search/page.txt
@@ -0,0 +1,5 @@
+{{object.title}}
+
+{% for cell in object.get_cells %}
+ {{ cell.render_for_search }}
+{% endfor %}
diff --git a/combo/settings.py b/combo/settings.py
index 98f18f2..63b5cad 100644
--- a/combo/settings.py
+++ b/combo/settings.py
@@ -55,6 +55,7 @@ INSTALLED_APPS = (
'django.contrib.messages',
'django.contrib.staticfiles',
'ckeditor',
+ 'haystack',
'gadjo',
'cmsplugin_blurp',
'combo.data',
@@ -122,6 +123,13 @@ MEDIA_URL = '/media/'
CKEDITOR_UPLOAD_PATH = 'uploads/'
+HAYSTACK_CONNECTIONS = {
+ 'default': {
+ 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
+ 'PATH': os.path.join(BASE_DIR, 'whoosh_index'),
+ },
+}
+
CKEDITOR_CONFIGS = {
'default': {
'toolbar_Own': [['Source', 'Format', '-', 'Bold', 'Italic'],