This repository has been archived by the owner on Jul 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_sites.py
76 lines (66 loc) · 2.76 KB
/
search_sites.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from django.contrib.flatpages.models import FlatPage
from feedinator.models import FeedEntry
from haystack import site
from haystack import indexes
from sunlightfoundation.presscenter.models import PressArticle, PressRelease
from wordpress.models import Post
#
# WordPress
#
class WordPressIndex(indexes.SearchIndex):
type = indexes.CharField(default='post')
text = indexes.CharField(document=True, model_attr='content', use_template=True)
summary = indexes.CharField(model_attr='excerpt')
title = indexes.CharField(model_attr='title')
link = indexes.CharField(model_attr='get_absolute_url')
def get_queryset(self):
return Post.objects.published()
site.register(Post, WordPressIndex)
#
# django feedinator
#
EXCLUDED_FEEDS = ('delicious-sunlightmedia','congresspedia','delicious-sunlightnewswatch',
'opensecrets','reporting','sunlightfoundation')
class FeedEntryIndex(indexes.SearchIndex):
type = indexes.CharField(default='feed')
text = indexes.CharField(document=True, model_attr='content', use_template=True)
summary = indexes.CharField(model_attr='summary')
feed = indexes.CharField(model_attr='feed')
title = indexes.CharField(model_attr='title')
link = indexes.CharField(model_attr='link')
author = indexes.CharField(model_attr='author_name')
def get_queryset(self):
return FeedEntry.objects.exclude(feed__codename__in=EXCLUDED_FEEDS)
site.register(FeedEntry, FeedEntryIndex)
#
# flatpages
#
class FlatPageIndex(indexes.SearchIndex):
type = indexes.CharField(default='page')
text = indexes.CharField(document=True, model_attr='content')
title = indexes.CharField(model_attr='title')
link = indexes.CharField(model_attr='url')
def get_queryset(self):
return FlatPage.objects.all()
site.register(FlatPage, FlatPageIndex)
#
# press
#
class PressArticleIndex(indexes.SearchIndex):
type = indexes.CharField(default='press_article')
text = indexes.CharField(document=True, model_attr='body', use_template=True)
title = indexes.CharField(model_attr='headline')
link = indexes.CharField(model_attr='get_absolute_url')
summary = indexes.CharField(model_attr='teaser')
def get_queryset(self):
return PressArticle.objects.filter(is_public=True)
site.register(PressArticle, PressArticleIndex)
class PressReleaseIndex(indexes.SearchIndex):
type = indexes.CharField(default='press_release')
text = indexes.CharField(document=True, model_attr='body')
title = indexes.CharField(model_attr='headline')
link = indexes.CharField(model_attr='get_absolute_url')
summary = indexes.CharField(model_attr='teaser')
def get_queryset(self):
return PressRelease.objects.filter(is_public=True)
site.register(PressRelease, PressReleaseIndex)