Using this form:

  veld = ['affiliation', 'country','year','journal','author']

   form = SQLFORM.factory(
        Field('k', label='Type in up to 5 keywords separated by '
'(spaces).',requires=IS_NOT_EMPTY()),
        Field('how', label='Search all or any of the
keywords',default='all', requires = IS_IN_SET(['any','all'])),
        Field('refine', label='Refine by search in another
field',default=None, requires= IS_IN_SET(veld)),
        Field('value', label='What to search for',default=None))

And the following function to build the keyword query (thanks to help
from this Massimo):

        h = request.vars.how
        if h == 'any':
            query = reduce(lambda
a,b:a|b,[db.sarua.keywords.lower().like('%'+ k
+'%')|db.sarua.title.lower().like('%'+k
+'%')|db.sarua.journal.lower().like('%'+k +'%') for k in
request.vars.k.lower().split()])
        else:
            query = reduce(lambda
a,b:a&b,[db.sarua.keywords.lower().like('%'+ k
+'%')|db.sarua.title.lower().like('%'+k
+'%')|db.sarua.journal.lower().like('%'+k +'%') for k in
request.vars.k.lower().split()])

I want to add the rest of the form to the query.  I have tried:

        r = request.vars.refine

        if not r :
            query = query
        else:
            query = query + '&' +
db.sarua[request.vars.refine.lower()].like('%'+request.vars.value.lower
+ '%')

but this is not working because the query is not of the type str:

    query = query + '&' +
db.sarua[request.vars.refine.lower()].like('%'+request.vars.value.lower
+ '%')
TypeError: unsupported operand type(s) for +: 'Query' and 'str'

How do I extend query built by lambda?

Regards
Johann
-- 
       "Every good gift and every perfect gift is from above,
      and cometh down from the Father of lights, with whom
      is no variableness, neither shadow of turning."
                             James 1:17

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to