def search(self, search_string, limit=None, offset=None): query = (db.session.query(IndexedCategory.id) .filter(IndexedCategory.title_vector.op('@@')( func.to_tsquery('simple', preprocess_ts_string(search_string)))) .limit(limit) .offset(offset)) return [x[0] for x in query]
def search(self, search_string, limit=None, offset=None): query = (db.session.query(IndexedCategory.id) .filter(IndexedCategory.title_vector.op('@@')( func.to_tsquery('simple', preprocess_ts_string(search_string)))) .limit(limit) .offset(offset)) return [x[0] for x in query]
def search(self, search_string, order_by='start'): if order_by == 'start': order = IndexedEvent.start_date.desc() elif order_by == 'id': order = IndexedEvent.id else: order = None return (db.session.query(IndexedEvent.id) .filter(IndexedEvent.title_vector.op('@@')( func.to_tsquery('simple', preprocess_ts_string(search_string)))) .order_by(order))
def title_matches(cls, search_string, exact=False): """Check whether the title matches a search string. To be used in a SQLAlchemy `filter` call. :param search_string: A string to search for :param exact: Whether to search for the exact string """ crit = db.func.to_tsvector('simple', cls.title).match(preprocess_ts_string(search_string), postgresql_regconfig='simple') if exact: crit = crit & cls.title.ilike('%{}%'.format(escape_like(search_string))) return crit
def title_matches(cls, search_string, exact=False): """Check whether the title matches a search string. To be used in a SQLAlchemy `filter` call. :param search_string: A string to search for :param exact: Whether to search for the exact string """ crit = db.func.to_tsvector('simple', cls.title).match( preprocess_ts_string(search_string), postgresql_regconfig='simple') if exact: crit = crit & cls.title.ilike(f'%{escape_like(search_string)}%') return crit
def fts_matches(column, search_string, *, exact=False): """Check whether a fts-indexed column matches a search string. To be used in a SQLAlchemy `filter` call. :param column: The column to search in :param search_string: A string to search for :param exact: Whether to search for the exact string """ crit = db.func.to_tsvector('simple', column).match( preprocess_ts_string(search_string), postgresql_regconfig='simple') if exact: crit = crit & column.ilike(escape_like(search_string)) return crit
def search(self, search_string, order_by='start'): if order_by == 'start': order = IndexedEvent.start_date.desc() elif order_by == 'id': order = IndexedEvent.id else: order = None return (db.session.query(IndexedEvent.id).join( Event, Event.id == IndexedEvent.id).filter(~Event.is_deleted).filter( IndexedEvent.title_vector.op('@@')(func.to_tsquery( 'simple', preprocess_ts_string(search_string)))).order_by(order))
def _contains(field, text): return (db.func.to_tsvector('simple', db.func.indico.indico_unaccent(field)).match( db.func.indico.indico_unaccent( preprocess_ts_string(text)), postgresql_regconfig='simple'))
def _contains(field, text): return (db.func.to_tsvector('simple', db.func.indico.indico_unaccent(field)) .match(db.func.indico.indico_unaccent(preprocess_ts_string(text)), postgresql_regconfig='simple'))