[web2py] expert_search=True

35 views
Skip to first unread message

Richard

unread,
Apr 24, 2014, 12:37:19 PM4/24/14
to web...@googlegroups.com
Hello,

I would improve default search widget a bit like that :

                if expert_search:
                   search_widget = lambda sfield, url: CAT(FORM(
                       TEXTAREA(_name='keywords',
                                _class='expert_search',
                                _value=request.vars.keywords,
                                _id=skeywords_id,
                                _onfocus="jQuery('#%s').change();jQuery('#%s').slideDown();" % (spanel_id, sfields_id) if advanced_search else ''
                       ),
                       INPUT(_type='submit', _value=T('Search'), _class="btn btn-default"),
                       INPUT(_type='submit', _value=T('Clear'), _class="btn btn-default",
                             _onclick="jQuery('#%s').val('');" % skeywords_id),
                       _method="GET", _action=url), search_menu)
               else:
                   search_widget = lambda sfield, url: CAT(FORM(
                       INPUT(_name='keywords',
                             _value=request.vars.keywords,
                             _id=skeywords_id,
                             _onfocus="jQuery('#%s').change();jQuery('#%s').slideDown();" % (spanel_id, sfields_id) if advanced_search else ''
                       ),
                       INPUT(_type='submit', _value=T('Search'), _class="btn btn-default"),
                       INPUT(_type='submit', _value=T('Clear'), _class="btn btn-default",
                             _onclick="jQuery('#%s').val('');" % skeywords_id),
                       _method="GET", _action=url), search_menu)

So the search query is easier to write for an "expert"...

But I didn't find where the search form get parsed... We need to strip line break of the textarea in order to have this feature.

Thanks

Richard

Richard Vézina

unread,
Apr 24, 2014, 1:14:26 PM4/24/14
to web2py-users
I just test, and it doesn't seem to make problem having line break...

The form didn't get parsed the way I thought... keywords is not empty in case there is query parameters in the search field (name keywords) then build_query() kicks in...

        if key and not ' ' in key and not '"' in key and not "'" in key:
            SEARCHABLE_TYPES = ('string', 'text', 'list:string')
            parts = [field.contains(
                key) for field in fields if field.type in SEARCHABLE_TYPES]

Not sure if the piece of code above is doing all the work or not...

Richard


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages