In order to get a query object you have to use the field objects and
not string representations of them, so you can not do
"(db.%s.%s.contains('%s'))" %(filname, term, request.vars[term]))

that should be
db[filname][term].contains(request.vars[term])

and since queries can be ANDed together, you can write

rv=dict([(k,v) for k,v in rvars.iteritems() if k<>'n'])
q=reduce(lambda a,b: (db.test[a].contains(rv[a])) &
(db.test[b].contains(rv[b])),rv)
search=db(q).select()

Denes.


On Oct 30, 5:01 pm, thylacine222 <thylacine...@gmail.com> wrote:
> Hi, I'm running this code right now:
>     querylist = []
>     for term in request.vars:
>         if term != 'n':
>                querylist.append("(db.%s.%s.contains('%s'))" %
> (filname, term, request.vars[term]))
>     queryterm = (' & '.join(querylist),)
>     search = db(*queryterm).select()
>
> The term in queryterm works perfectly if I use it manually on the
> database administration page, but when I run this code, I get "Key
> Error:foo" where foo is a field that I'm querying.
>
> Is there any easier way to do this? I'm not sure why I keep getting
> this error.

Reply via email to