Beispiel #1
0
 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]
Beispiel #2
0
 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]
Beispiel #3
0
    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))
Beispiel #4
0
    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
Beispiel #5
0
    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
Beispiel #6
0
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
Beispiel #7
0
    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))
Beispiel #8
0
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'))
Beispiel #9
0
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'))