Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Haystack is storing our data in ES now

  • Loading branch information...
commit 47fdee49af4b82c5f09ac2b40b7ed05d7ba84445 1 parent 57026d9
@davedash davedash authored
View
24 apps/feedback/search_indexes.py
@@ -0,0 +1,24 @@
+from haystack import indexes
+from celery_haystack.indexes import CelerySearchIndex
+
+from feedback.models import Opinion
+
+
+class OpinionIndex(CelerySearchIndex, indexes.Indexable):
+ text = indexes.CharField(document=True, use_template=True)
+ created = indexes.DateTimeField(model_attr='created')
+ url = indexes.CharField(model_attr='url')
+ user_agent = indexes.CharField(model_attr='user_agent')
+ product = indexes.CharField(model_attr='product')
+ version = indexes.CharField(model_attr='version')
+ platform = indexes.CharField(model_attr='platform')
+ locale = indexes.CharField(model_attr='locale')
+ manufacturer = indexes.CharField(model_attr='manufacturer')
+ device = indexes.CharField(model_attr='device')
+
+ def get_model(self):
+ return Opinion
+
+ def index_queryset(self):
+ """Used when the entire index for model is updated."""
+ return self.get_model().objects.filter()
View
2  apps/feedback/templates/search/indexes/feedback/opinion_text.txt
@@ -0,0 +1,2 @@
+{{ object.description }}
+{{ object.url }}
View
4 requirements/prod.txt
@@ -41,3 +41,7 @@ django-celery
# Sphinx API
-e git://github.com/jsocol/sphinxapi.git#egg=sphinxapi
+
+# ElasticSearch
+haystack
+requests
View
10 settings/base.py
@@ -139,6 +139,8 @@
'annoying',
'cronjobs',
+ 'haystack', # for search
+ 'celery_haystack', # for lazy indexing
'django.contrib.admin',
'django.contrib.sites',
@@ -208,3 +210,11 @@
DASHBOARD_THRESHOLD = 800
DASHBOARD_THRESHOLD_MOBILE = 120
SESSION_COOKIE_SECURE = True
+
+HAYSTACK_CONNECTIONS = {
+ 'default': {
+ 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
+ 'URL': 'http://127.0.0.1:9200/',
+ 'INDEX_NAME': 'input',
+ },
+}
View
5 settings_local.py-dist → settings/local.py-dist
@@ -43,3 +43,8 @@ STATSD_HOST = 'localhost'
STATSD_PORT = 8125
STATSD_PREFIX = 'input'
SESSION_COOKIE_SECURE = False
+
+# change this to the elasticsearch host
+HAYSTACK_CONNECTIONS['default']['URL'] = 'http://127.0.0.1:9200/'
+# append -dev, -stage if sharing with other environments, otherwise leave as is
+# HAYSTACK_CONNECTIONS['default']['INDEX_NAME'] = 'input'
Please sign in to comment.
Something went wrong with that request. Please try again.