Permalink
Browse files

Making poor progress on search. Can't even query yet.

  • Loading branch information...
1 parent 55d1e24 commit bb1d654dab22b0750636646ef43173775f708a32 @samuelclay committed Jul 13, 2012
Showing with 28 additions and 15 deletions.
  1. +10 −0 apps/rss_feeds/models.py
  2. +17 −8 apps/search/models.py
  3. +1 −7 settings.py
View
@@ -18,6 +18,7 @@
from mongoengine.queryset import OperationError
from mongoengine.base import ValidationError
from apps.rss_feeds.tasks import UpdateFeeds, PushFeeds
+from apps.search.models import SearchStarredStory
from utils import json_functions as json
from utils import feedfinder, feedparser
from utils import urlnorm
@@ -1349,6 +1350,15 @@ def save(self, *args, **kwargs):
self.story_original_content_z = zlib.compress(self.story_original_content)
self.story_original_content = None
super(MStarredStory, self).save(*args, **kwargs)
+
+ def index_for_search(self):
+ story_content = zlib.decompress(self.story_content_z)
+ SearchStarredStory.index(user_id=self.user_id,
+ story_id=self.story_guid,
+ story_title=self.story_title,
+ story_content=story_content,
+ story_author=self.story_author_name,
+ story_date=self.story_date)
class MFeedFetchHistory(mongo.Document):
View
@@ -1,13 +1,14 @@
import pyes
from django.conf import settings
-class Search:
+class SearchStarredStory:
- ES = settings.ELASTICSEARCH
+ ES = pyes.ES(settings.ELASTICSEARCH_HOSTS)
+ name = "starred-stories"
@classmethod
def create_elasticsearch_mapping(cls):
- cls.ES.create_index("story-index")
+ cls.ES.create_index("%s-index" % cls.name)
mapping = {
'title': {
'boost': 2.0,
@@ -36,22 +37,30 @@ def create_elasticsearch_mapping(cls):
'date': {
'store': 'yes',
'type': 'date',
+ },
+ 'user_ids': {
+ 'index': 'not_analyzed',
+ 'store': 'yes',
+ 'type': 'integer',
+ 'index_name': 'user_id'
}
}
- cls.ES.put_mapping("story-type", {'properties': mapping}, ["story-index"])
+ cls.ES.put_mapping("%s-type" % cls.name, {'properties': mapping}, ["%s-index" % cls.name])
@classmethod
- def index(cls, story_id, story_title, story_content, story_author, story_date):
+ def index(cls, user_id, story_id, story_title, story_content, story_author, story_date):
doc = {
"content": story_content,
"title": story_title,
"author": story_author,
- "date": story_date
+ "date": story_date,
+ "user_ids": user_id,
}
- cls.ES.index(doc, "story-index", "story-type", story_id)
+ cls.ES.index(doc, "%s-index" % cls.name, "%s-type" % cls.name, story_id)
@classmethod
- def query(cls, text):
+ def query(cls, user_id, text):
+ cls.ES.refresh()
q = pyes.query.StringQuery(text)
results = cls.ES.search(q)
return results
View
@@ -3,7 +3,6 @@
import os
from mongoengine import connect
import redis
-import pyes
from utils import jammit
# ===================
@@ -226,6 +225,7 @@
'apps.push',
'apps.social',
'apps.oauth',
+ 'apps.search',
'south',
'utils',
'vendor',
@@ -400,11 +400,5 @@ def custom_show_toolbar(request):
JAMMIT = jammit.JammitAssets(NEWSBLUR_DIR)
-# =================
-# = Elasticsearch =
-# =================
-
-ELASTICSEARCH = pyes.ES(ELASTICSEARCH_HOSTS)
-
if DEBUG:
MIDDLEWARE_CLASSES += ('utils.mongo_raw_log_middleware.SqldumpMiddleware',)

0 comments on commit bb1d654

Please sign in to comment.