Look how web2py handles db.table.field.belongs(list). You can add a db.table.field.contains_text(....) using a similar text. You will need something like this in dal.py
class Expression(object): def contains_text(self, value): return Query(self.db, self.db._adapter.CONTAINS_TEXT, self, value) def contains_text(...) class BaseAdapter(ConnectionPool): def CONTAINS_TEXT(self,first,second): raise NotImplementedError class PostgreSQLAdapter(BaseAdapter): def CONTAINS_TEXT(self,first,second): a,b = self.expand(first),second return "to_tsvector('%s', description) @@ to_tsquery('%s', '%s')" % (a,a,b) not sure about the last method. Will need testing. On Jul 31, 2:29 pm, pbreit <pbreitenb...@gmail.com> wrote: > I'm starting to implement Postgres text search and am not quite sure how to > build a complex query. The full text part is a string and then, of course, > the other components are Query types. How would I combine them? > > Example: > > items = db(("to_tsvector('english', description) @@ > to_tsquery('english', '%s')" % q) & > (db.item.status=='active')).select(db.item.ALL, > orderby=orderby) > > Errors: > > TypeError: unsupported operand type(s) for &: 'str' and 'Query' > > Do I have to write out the whole query as a string in SQL?