Updating search for saved stories to search fuzzy queries. Connected to UI.

This commit is contained in:
Samuel Clay 2012-12-20 16:07:22 -08:00
parent 93e3a76087
commit 612a349239
4 changed files with 32 additions and 8 deletions

View file

@ -18,7 +18,7 @@ from django.core.mail import mail_admins
from django.core.validators import email_re
from django.core.mail import EmailMultiAlternatives
from django.contrib.sites.models import Site
from mongoengine.queryset import OperationError, Q
from mongoengine.queryset import OperationError
from apps.recommendations.models import RecommendedFeed
from apps.analyzer.models import MClassifierTitle, MClassifierAuthor, MClassifierFeed, MClassifierTag
from apps.analyzer.models import apply_classifier_titles, apply_classifier_feeds
@ -29,6 +29,7 @@ from apps.reader.models import UserSubscription, UserSubscriptionFolders, MUserS
from apps.reader.forms import SignupForm, LoginForm, FeatureForm
from apps.rss_feeds.models import MFeedIcon
from apps.statistics.models import MStatistics
from apps.search.models import SearchStarredStory
try:
from apps.rss_feeds.models import Feed, MFeedPage, DuplicateFeed, MStory, MStarredStory
except:
@ -635,11 +636,11 @@ def load_starred_stories(request):
if page: offset = limit * (page - 1)
if query:
results = SearchStarredStory.query(user.pk, query)
story_ids = [result.db_id for result in results]
mstories = MStarredStory.objects(
Q(user_id=user.pk) &
(Q(story_title__icontains=query) |
Q(story_content__icontains=query) |
Q(story_author_name__icontains=query))
user_id=user.pk,
id__in=story_ids
).order_by('-starred_date')[offset:offset+limit]
else:
mstories = MStarredStory.objects(

View file

@ -1500,6 +1500,8 @@ class MStarredStory(mongo.Document):
self.story_original_content_z = zlib.compress(self.story_original_content)
self.story_original_content = None
super(MStarredStory, self).save(*args, **kwargs)
self.index_for_search()
def index_for_search(self):
story_content = zlib.decompress(self.story_content_z)
@ -1508,7 +1510,8 @@ class MStarredStory(mongo.Document):
story_title=self.story_title,
story_content=story_content,
story_author=self.story_author_name,
story_date=self.story_date)
story_date=self.story_date,
db_id=str(self.id))
@property
def guid_hash(self):

View file

@ -28,7 +28,12 @@ class SearchStarredStory:
'boost': 1.0,
'index': 'analyzed',
'store': 'yes',
'type': 'string',
'type': 'string',
},
'db_id': {
'index': 'not_analyzed',
'store': 'yes',
'type': 'string',
},
'feed_id': {
'store': 'yes',
@ -48,13 +53,14 @@ class SearchStarredStory:
cls.ES.put_mapping("%s-type" % cls.name, {'properties': mapping}, ["%s-index" % cls.name])
@classmethod
def index(cls, user_id, 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, db_id):
doc = {
"content": story_content,
"title": story_title,
"author": story_author,
"date": story_date,
"user_ids": user_id,
"db_id": db_id,
}
cls.ES.index(doc, "%s-index" % cls.name, "%s-type" % cls.name, story_id)
@ -63,4 +69,17 @@ class SearchStarredStory:
cls.ES.refresh()
q = pyes.query.StringQuery(text)
results = cls.ES.search(q)
if not results.total:
q = pyes.query.FuzzyQuery('title', text)
results = cls.ES.search(q)
if not results.total:
q = pyes.query.FuzzyQuery('content', text)
results = cls.ES.search(q)
if not results.total:
q = pyes.query.FuzzyQuery('author', text)
results = cls.ES.search(q)
return results

View file

@ -1313,6 +1313,7 @@
this.switch_taskbar_view(this.story_view);
this.setup_mousemove_on_views();
this.make_feed_title_in_stories();
this.hide_stories_error();
this.model.fetch_starred_stories(1, _.bind(this.post_open_starred_stories, this),
this.show_stories_error, true);