Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 13115d7ad638e2d9a446f0031206da76bbbb5306 Author: Bohuslav Kabrda bkabrda@redhat.com Date: Thu Feb 14 14:09:43 2013 +0100
Start using flask-whooshee
coprs_frontend/coprs/__init__.py | 3 ++ coprs_frontend/coprs/config.py | 2 + coprs_frontend/coprs/logic/coprs_logic.py | 8 ++++- coprs_frontend/coprs/whoosheers.py | 56 +++++++++++++++++++++++++++++ requirements.txt | 1 + 5 files changed, 69 insertions(+), 1 deletions(-)
diff --git a/coprs_frontend/coprs/__init__.py b/coprs_frontend/coprs/__init__.py index f239b65..6a9290c 100644 --- a/coprs_frontend/coprs/__init__.py +++ b/coprs_frontend/coprs/__init__.py @@ -5,6 +5,7 @@ import flask
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.openid import OpenID +from flask.ext.whooshee import Whooshee
app = flask.Flask(__name__)
@@ -17,10 +18,12 @@ else:
oid = OpenID(app, app.config['OPENID_STORE']) db = SQLAlchemy(app) +whooshee = Whooshee(app)
import coprs.filters import coprs.log import coprs.models +import coprs.whoosheers
from coprs.views import api_ns from coprs.views.api_ns import api_general diff --git a/coprs_frontend/coprs/config.py b/coprs_frontend/coprs/config.py index 6218ea9..b5ee63e 100644 --- a/coprs_frontend/coprs/config.py +++ b/coprs_frontend/coprs/config.py @@ -5,6 +5,7 @@ class Config(object): DATA_DIR = os.path.join(os.path.dirname(__file__), '../../data') DATABASE = os.path.join(DATA_DIR, 'copr.db') OPENID_STORE = os.path.join(DATA_DIR, 'openid_store') + WHOOSHEE_DIR = os.path.join(DATA_DIR, 'whooshee') SECRET_KEY = 'THISISNOTASECRETATALL' BACKEND_PASSWORD = 'thisisbackend'
@@ -33,6 +34,7 @@ class UnitTestConfig(Config): CSRF_ENABLED = False DATABASE = os.path.abspath('tests/data/copr.db') OPENID_STORE = os.path.abspath('tests/data/openid_store') + WHOOSHEE_DIR = os.path.abspath('tests/data/whooshee')
# SQLAlchemy SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.abspath(DATABASE) diff --git a/coprs_frontend/coprs/logic/coprs_logic.py b/coprs_frontend/coprs/logic/coprs_logic.py index afdeadb..0a1d373 100644 --- a/coprs_frontend/coprs/logic/coprs_logic.py +++ b/coprs_frontend/coprs/logic/coprs_logic.py @@ -4,6 +4,7 @@ from coprs import db from coprs import exceptions from coprs import helpers from coprs import models +from coprs import whoosheers
class CoprsLogic(object): """Used for manipulating Coprs. All methods accept user object as a first argument, as this may be needed in future.""" @@ -51,7 +52,12 @@ class CoprsLogic(object):
@classmethod def get_multiple_fulltext(cls, user, search_string): - query = models.Copr.query.fulltext(models.Copr.copr_ts_col, search_string) + try: + ids = whoosheers.CoprUserWhoosheer.search(search_string, values_of='copr_id') + except ValueError as e: + # too short search_string + ids = [] + query = models.Copr.query.filter(models.Copr.id.in_(ids)) return query
@classmethod diff --git a/coprs_frontend/coprs/whoosheers.py b/coprs_frontend/coprs/whoosheers.py new file mode 100644 index 0000000..d5da048 --- /dev/null +++ b/coprs_frontend/coprs/whoosheers.py @@ -0,0 +1,56 @@ +import re +import os + +import whoosh +import whoosh.fields +import whoosh.index +import whoosh.qparser + +from flask.ext.sqlalchemy import models_committed +from flask.ext.whooshee import AbstractWhoosheer + +from coprs import app +from coprs import db +from coprs import models +from coprs import whooshee + +@whooshee.register_whoosheer +class CoprUserWhoosheer(AbstractWhoosheer): + schema = whoosh.fields.Schema( + copr_id = whoosh.fields.NUMERIC(stored=True, unique=True), + user_id = whoosh.fields.NUMERIC(stored=True), + username = whoosh.fields.TEXT(), + coprname = whoosh.fields.TEXT(), + description = whoosh.fields.TEXT(), + instructions = whoosh.fields.TEXT()) + + models = [models.Copr, models.User] + index = None + + @classmethod + def update_user(cls, writer, user): + # TODO: this is not needed now, as users can't change names, but may be needed later + pass + + @classmethod + def update_copr(cls, writer, copr): + writer.update_document(copr_id=copr.id, + user_id=copr.owner.id, + username=copr.owner.name, + coprname=copr.name, + description=copr.description, + instructions=copr.instructions) + + @classmethod + def insert_user(cls, writer, user): + # nothing, user doesn't have coprs yet + pass + + @classmethod + def insert_copr(cls, writer, copr): + writer.add_document(copr_id=copr.id, + user_id=copr.owner.id, + username=copr.owner.name, + coprname=copr.name, + description=copr.description, + instructions=copr.instructions) diff --git a/requirements.txt b/requirements.txt index d3fb7dd..6217ff4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ flask-wtf alembic pytest flask-script +flask-whooshee
copr-devel@lists.fedorahosted.org