From b51a054c1c185f294d92029a66a70ad2727cad5a Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Fri, 17 Jul 2015 14:01:38 -0700 Subject: [PATCH] Upgrading elasticsearch to 1.7.0, pyes to 0.99.5, and modern querying for stories. Needs a reindex. Still need to do feeds. --- apps/search/management/commands/index_stories.py | 12 +++++++++++- apps/search/models.py | 10 +++++----- config/requirements.txt | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/search/management/commands/index_stories.py b/apps/search/management/commands/index_stories.py index 2d16ee002..4b29b193e 100644 --- a/apps/search/management/commands/index_stories.py +++ b/apps/search/management/commands/index_stories.py @@ -1,16 +1,26 @@ import re from django.core.management.base import BaseCommand from django.contrib.auth.models import User -from apps.rss_feeds.models import Feed +from apps.rss_feeds.models import Feed, MStory from apps.reader.models import UserSubscription from optparse import make_option class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option("-u", "--user", dest="user", nargs=1, help="Specify user id or username"), + make_option("-R", "--reindex", dest="reindex", action="store_true", help="Drop index and reindex all stories."), + ) def handle(self, *args, **options): + if options['reindex']: + MStory.index_all_for_search() + return + + if not options['user']: + print "Missing user. Did you want to reindex everything? Use -R." + return + if re.match(r"([0-9]+)", options['user']): user = User.objects.get(pk=int(options['user'])) else: diff --git a/apps/search/models.py b/apps/search/models.py index a84004bb8..c1ee016cb 100644 --- a/apps/search/models.py +++ b/apps/search/models.py @@ -202,28 +202,28 @@ class SearchStory: 'index': 'analyzed', 'store': 'no', 'type': 'string', - 'analyzer': 'snowball', + 'analyzer': 'standard', }, 'content': { 'boost': 1.0, 'index': 'analyzed', 'store': 'no', 'type': 'string', - 'analyzer': 'snowball', + 'analyzer': 'simple', }, 'tags': { 'boost': 2.0, 'index': 'analyzed', 'store': 'no', 'type': 'string', - 'analyzer': 'snowball', + 'analyzer': 'standard', }, 'author': { 'boost': 1.0, 'index': 'analyzed', 'store': 'no', 'type': 'string', - 'analyzer': 'keyword', + 'analyzer': 'simple', }, 'feed_id': { 'store': 'no', @@ -272,7 +272,7 @@ class SearchStory: cls.ES.indices.refresh() sort = "date:desc" if order == "newest" else "date:asc" - string_q = pyes.query.StringQuery(query, default_operator="AND") + string_q = pyes.query.QueryStringQuery(query, default_operator="AND") feed_q = pyes.query.TermsQuery('feed_id', feed_ids[:1000]) q = pyes.query.BoolQuery(must=[string_q, feed_q]) try: diff --git a/config/requirements.txt b/config/requirements.txt index d6bc95385..87ba30084 100755 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -27,7 +27,7 @@ mongoengine==0.8.2 nltk==2.0.5 oauth2==1.5.211 psutil==2.1.0 -pyes==0.90.1 +pyes==0.99.5 simplejson==3.4.0 pyflakes==0.6.1 pymongo==2.6