Search is a complex issues how to implement really depends on the type
of data, size of data and number of users.

A simple minimalist solution is

#view default/index.html
<form action="" method="get"><input name="keywords"><input
type="submit"></form>
{{=results}}

#controller default.py
def index():
    keywords=[]
    if request.vars.keywords:
        keywords = [x for x in keywords.split() if len(x)>3]
    if keywords:
        query1=reduce(lambda a,b:a|b,[db.table.field1.like('%'+k+'%')
for k in keywords])
        query2=reduce(lambda a,b:a|b,[db.table.field1.like('%'+k+'%')
for k in keywords])
        results = db(query1|query2).select()
    else:
        results = ''
    return dict(results=results)

On Feb 2, 4:13 am, Al <albertsec...@gmail.com> wrote:
> I am trying to incorporate a "Search" function into my web2py
> application. I have found similar thing in the sample appliance such
> as the KPAX and the C.R.M application, could someone detail how I
> could copy code from these apps. Is there a way to trace the relevant
> section of code for the search function (ajax, controllers, views,
> etc), I have spent the whole day and can't get it to work. I just want
> to search on two fields - Title and Keywords of a table - a generic
> search would also be good if the performance is not too bad
>
> Al

-- 
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