Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 2158a19492b02d91628d7c7bfc12f9b2771c7f4d Author: Bohuslav Kabrda bkabrda@redhat.com Date: Thu Feb 14 14:37:19 2013 +0100
Drop the previous fulltext search now that whoosh is working
...4b45f5476_remove_fulltext_in_favor_of_whoosh.py | 31 +++++++++++++ coprs_frontend/coprs/models.py | 47 -------------------- coprs_frontend/coprs/sql_custom.py | 26 ----------- 3 files changed, 31 insertions(+), 73 deletions(-)
diff --git a/coprs_frontend/alembic/versions/1ee4b45f5476_remove_fulltext_in_favor_of_whoosh.py b/coprs_frontend/alembic/versions/1ee4b45f5476_remove_fulltext_in_favor_of_whoosh.py new file mode 100644 index 0000000..a5e9df4 --- /dev/null +++ b/coprs_frontend/alembic/versions/1ee4b45f5476_remove_fulltext_in_favor_of_whoosh.py @@ -0,0 +1,31 @@ +"""empty message + +Revision ID: 1ee4b45f5476 +Revises: 3a035889852c +Create Date: 2013-02-14 14:11:50.624673 + +""" + +# revision identifiers, used by Alembic. +revision = '1ee4b45f5476' +down_revision = '3a035889852c' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.drop_column('copr', u'copr_ts_col') + if op.get_bind().dialect.name == 'postgresql': + op.execute('DROP trigger IF EXISTS copr_ts_update ON copr') + elif op.get_bind().dialect.name == 'sqlite': + op.execute('DROP trigger IF EXISTS copr_ts_update') + op.execute('DROP trigger IF EXISTS copr_ts_insert') + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.add_column('copr', sa.Column(u'copr_ts_col', sa.TEXT(), nullable=True)) + ### end Alembic commands ### diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py index 18d8dfe..81d23df 100644 --- a/coprs_frontend/coprs/models.py +++ b/coprs_frontend/coprs/models.py @@ -6,7 +6,6 @@ from sqlalchemy.ext.associationproxy import association_proxy from coprs import constants from coprs import db from coprs import helpers -from coprs import sql_custom
class Serializer(object): def to_dict(self, options = {}): @@ -108,8 +107,6 @@ class User(db.Model, Serializer):
class Copr(db.Model, Serializer): - query_class = sql_custom.FullTextQuery - id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(100), nullable = False) repos = db.Column(db.Text) @@ -118,9 +115,6 @@ class Copr(db.Model, Serializer): instructions = db.Column(db.Text) # duplicate information, but speeds up a lot and makes queries simpler build_count = db.Column(db.Integer, default = 0) - # fulltext - copr_ts_col = db.Column(sql_custom.Tsvector) - copr_ts_idx = db.Index('copr_ts_col', postgresql_using='gin')
# relations owner_id = db.Column(db.Integer, db.ForeignKey('user.id')) @@ -143,47 +137,6 @@ class Copr(db.Model, Serializer): def instructions_or_not_filled(self): return self.instructions or 'Instructions not filled in by author.'
-### fulltext search trigger for copr -# postgres -sqlalchemy.event.listen( - Copr.__table__, - 'after_create', - sqlalchemy.schema.DDL("CREATE TRIGGER copr_ts_update BEFORE INSERT OR UPDATE \ - ON copr \ - FOR EACH ROW EXECUTE PROCEDURE \ - tsvector_update_trigger(copr_ts_col, 'pg_catalog.english', name, description, instructions);").\ - execute_if(dialect='postgresql') -) - -# sqlite -sqlalchemy.event.listen( - Copr.__table__, - 'after_create', - sqlalchemy.schema.DDL("CREATE TRIGGER copr_ts_update \ - AFTER UPDATE OF name, description, instructions \ - ON copr \ - FOR EACH ROW \ - BEGIN \ - UPDATE copr SET copr_ts_col = coalesce(name, '') || ' ' || \ - coalesce(description, '') || ' ' || coalesce(instructions, ''); \ - END;").\ - execute_if(dialect='sqlite') -) - -sqlalchemy.event.listen( - Copr.__table__, - 'after_create', - sqlalchemy.schema.DDL("CREATE TRIGGER copr_ts_insert \ - AFTER INSERT \ - ON copr \ - FOR EACH ROW \ - BEGIN \ - UPDATE copr SET copr_ts_col = coalesce(name, '') || ' ' || \ - coalesce(description, '') || ' ' || coalesce(instructions, ''); \ - END;").\ - execute_if(dialect='sqlite') -) - class CoprPermission(db.Model, Serializer): # 0 = nothing, 1 = asked for, 2 = approved # not using enum, as that translates to varchar on some DBs diff --git a/coprs_frontend/coprs/sql_custom.py b/coprs_frontend/coprs/sql_custom.py deleted file mode 100644 index 3be56ed..0000000 --- a/coprs_frontend/coprs/sql_custom.py +++ /dev/null @@ -1,26 +0,0 @@ -from sqlalchemy import func -from sqlalchemy import types -from sqlalchemy.ext import compiler - -from coprs import db - -class Tsvector(types.UnicodeText): - # TODO: define the custom operator to perform fulltext searches ? - pass - -@compiler.compiles(Tsvector, 'postgresql') -def compile_tsvector(element, compiler, **kw): - return 'tsvector' - -@compiler.compiles(Tsvector, 'sqlite') -def compile_tsvector(element, compiler, **kw): - return 'text' - - -class FullTextQuery(db.Query): - def fulltext(self, column, search_string): - if db.engine.dialect.name == 'postgresql': - search_with_or = ' | '.join(search_string.split()) - return self.filter(column.op('@@@')(func.to_tsquery(search_with_or))) - else: - return self.filter(column.like('%{0}%'.format(search_string)))
copr-devel@lists.fedorahosted.org