aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-13 00:42:56 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-13 00:42:56 +0200
commitcc92bc3d4e72c8e50e0478ada930425e14701307 (patch)
tree05d242d7547c5e80176494c918c879a64e168dc3 /pyaggr3g470r
parentHTML export now working on Heroku. (diff)
downloadnewspipe-cc92bc3d4e72c8e50e0478ada930425e14701307.tar.gz
newspipe-cc92bc3d4e72c8e50e0478ada930425e14701307.tar.bz2
newspipe-cc92bc3d4e72c8e50e0478ada930425e14701307.zip
Whoosh search is now working (but not on Heroku).
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/feedgetter.py14
-rw-r--r--pyaggr3g470r/search.py14
-rw-r--r--pyaggr3g470r/templates/search.html6
-rw-r--r--pyaggr3g470r/views.py33
4 files changed, 38 insertions, 29 deletions
diff --git a/pyaggr3g470r/feedgetter.py b/pyaggr3g470r/feedgetter.py
index cf0cd44c..c5bac3c8 100644
--- a/pyaggr3g470r/feedgetter.py
+++ b/pyaggr3g470r/feedgetter.py
@@ -171,13 +171,13 @@ class FeedGetter(object):
user_id=self.user.id, feed_id=feed.id)
articles.append(article)
- # add the article to the Whoosh index
- """
- try:
- search.add_to_index([article], feed)
- except Exception as e:
- pyaggr3g470r_log.error("Whoosh error.")
- pass"""
+ # add the article to the Whoosh index only if we are not on Heroku
+ if not conf.ON_HEROKU:
+ try:
+ search.add_to_index([article], feed)
+ except Exception as e:
+ pyaggr3g470r_log.error("Whoosh error.")
+ pass
# email notification
if conf.MAIL_ENABLED and feed.email_notification:
diff --git a/pyaggr3g470r/search.py b/pyaggr3g470r/search.py
index 859d317b..9000b477 100644
--- a/pyaggr3g470r/search.py
+++ b/pyaggr3g470r/search.py
@@ -41,10 +41,10 @@ import models
indexdir = "./pyaggr3g470r/var/indexdir"
-schema = Schema(title=TEXT(stored=True), \
+schema = Schema(title=TEXT, \
content=TEXT, \
- article_id=TEXT(stored=True), \
- feed_id=TEXT(stored=True))
+ article_id=NUMERIC(int, stored=True), \
+ feed_id=NUMERIC(int, stored=True))
def create_index(feeds):
"""
@@ -58,8 +58,8 @@ def create_index(feeds):
for article in feed.articles:
writer.add_document(title=article.title, \
content=utils.clear_string(article.content), \
- article_id=str(article.id).decode(), \
- feed_id=str(feed.oid).decode())
+ article_id=article.id, \
+ feed_id=feed.id)
writer.commit()
def add_to_index(articles, feed):
@@ -78,8 +78,8 @@ def add_to_index(articles, feed):
for article in articles:
writer.add_document(title=article.title, \
content=utils.clear_string(article.content), \
- article_id=str(article.id).decode(), \
- feed_id=str(feed.oid).decode())
+ article_id=article.id, \
+ feed_id=feed.id)
writer.commit()
def delete_article(feed_id, article_id):
diff --git a/pyaggr3g470r/templates/search.html b/pyaggr3g470r/templates/search.html
index e589ad9a..36076b14 100644
--- a/pyaggr3g470r/templates/search.html
+++ b/pyaggr3g470r/templates/search.html
@@ -18,7 +18,7 @@
<a href="/edit_feed/{{ feed.oid }}"><i class="glyphicon glyphicon-edit" title="Edit this feed"></i></a>
</div>
</div>
- {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %}
+ {% for number in range(0, feed.articles.all()|length-(feed.articles.all()|length % 3), 3) %}
<div class="row">
{% for n in range(number, number+3) %}
<div class="col-xs-6 col-sm-4 col-md-4">
@@ -30,9 +30,9 @@
{% endfor %}
</div>
{% endfor %}
- {% if feed.articles|length % 3 != 0 %}
+ {% if feed.articles.all()|length % 3 != 0 %}
<div class="row">
- {% for n in range(feed.articles|length-(feed.articles|length % 3), feed.articles|length) %}
+ {% for n in range(feed.articles.all()|length-(feed.articles.all()|length % 3), feed.articles.all()|length) %}
<div class="col-xs-6 col-sm-4 col-md-4">
{% if feed.articles[n].readed %}<h3>{% else %}<h1>{% endif %}
<a href="/article/{{ feed.articles[n].id }}">{{ feed.articles[n].title|safe }}</a>
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index a38dffcd..69552108 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -39,7 +39,8 @@ import utils
import export
import feedgetter
import models
-#import search as fastsearch
+if not conf.ON_HEROKU:
+ import search as fastsearch
from forms import SigninForm, AddFeedForm, ProfileForm
from pyaggr3g470r import app, db
from pyaggr3g470r.models import User, Feed, Article, Role
@@ -382,10 +383,14 @@ def index_database():
"""
Index all the database.
"""
- user = models.User.objects(email=g.user.email).first()
- #fastsearch.create_index(user.feeds)
- flash('Database indexed.', 'success')
- return redirect(url_for('home'))
+ if not conf.ON_HEROKU:
+ user = User.query.filter(User.id == g.user.id).first()
+ fastsearch.create_index(user.feeds)
+ flash('Database indexed.', 'success')
+ return redirect(url_for('home'))
+ else:
+ flash('Option not available on Heroku.', 'success')
+ return redirect(url_for('home'))
@app.route('/export/', methods=['GET'])
@login_required
@@ -425,20 +430,24 @@ def search():
if conf.ON_HEROKU:
flash("Full text search is not yet implemented for Heroku.", "warning")
return redirect(url_for('home'))
- user = models.User.objects(email=g.user.email).first()
+ user = User.query.filter(User.id == g.user.id).first()
result = []
query = request.args.get('query', None)
if query != None:
results, nb_articles = fastsearch.search(query)
for feed_id in results:
for feed in user.feeds:
- if str(feed.oid) == feed_id:
- feed.articles = []
+ if feed.id == feed_id:
+ new_feed = Feed()
+ new_feed.id = feed.id
+ new_feed.title = feed.title
+ new_feed.articles = []
for article_id in results[feed_id]:
- current_article = models.Article.objects(id=article_id).first()
- feed.articles.append(current_article)
- feed.articles = sorted(feed.articles, key=lambda t: t.date, reverse=True)
- result.append(feed)
+ current_article = Article.query.filter(Article.user_id == g.user.id, Article.id == article_id).first()
+ new_feed.articles.append(current_article)
+ new_feed.articles = sorted(new_feed.articles, key=lambda t: t.date, reverse=True)
+ result.append(new_feed)
+ break
return render_template('search.html', feeds=result, nb_articles=nb_articles, query=query)
@app.route('/management/', methods=['GET', 'POST'])
bgstack15