47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
# combo - content management system
|
|
# Copyright (C) 2014-2017 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 haystack.exceptions import SkipDocument
|
|
|
|
from .models import Page, CellBase, ExternalLinkSearchItem
|
|
|
|
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()
|
|
|
|
def prepare(self, obj):
|
|
if not obj.is_visible(user=None):
|
|
raise SkipDocument()
|
|
return super(PageIndex, self).prepare(obj)
|
|
|
|
|
|
class ExternalLinkSearchIndex(indexes.SearchIndex, indexes.Indexable):
|
|
title = indexes.CharField(model_attr='title', boost=1.5)
|
|
text = indexes.CharField(model_attr='text', document=True)
|
|
url = indexes.CharField(model_attr='url', indexed=False)
|
|
|
|
def get_model(self):
|
|
return ExternalLinkSearchItem
|