Example #1
0
    def find_books(self):
        """
        searches for books where keyword is present in title or author name
        """
        search_query = unicode(self.search_input.data)
        q = u'%{}%'.format(search_query)

        # used for dummy emulation of caseinsensetive search
        qC = u'%{}%'.format(capfirst(search_query))

        books = Book.query.filter(db.or_(
                     Book.authors.any(db.or_(
                         Author.name.like(q),
                         Author.name.like(qC))),
                     Book.title.like(q),
                     Book.title.like(qC)),)

        return books
Example #2
0
    def case_insensetive_get_authors_where_name_contains(q):
        """
        Implements case insensetive (ok, not case insensetive, 
        but results are near normal) unicode like search on sqlite

        It's still not ideal, but it's better than previous implementation
        If app should work with dbs other than sqlite it probably should also
        check config

        may be there are simple SQlite config solution, but i couldn't
        find it in apropriate time
        """
        q = unicode(q)
        authors = Author.query.filter(
            db.or_(Author.name.like(u'%{}%'.format(q)),
                   Author.name.like(u'%{}%'.format(capfirst(q))))
            )
        return authors