Thanks Massimo, however, using set() I assure distict elements, using your
LAMBDA solution, entries may duplicate.
SEARCH to plugin_wiki is running here :
http://web2pybrasil.appspot.com/cursoweb2py/

I need to search in different fields using a %LIKE% operator, my code now
needs some improvement to be more DRY,
and a way to cache search or create a table to store indexes.



search pages in GAE:

        found = set()
        string = request.vars.search

        if string:
            #need to encapsulate all search below in a single function
            #search in slug
            pages =
db(db.plugin_wiki_page.id>0).select(db.plugin_wiki_page.slug)
#how to cache pages object?
            for page in pages:
                if page.slug.find(string) > -1:
                    found.add(page.slug)

            #search in page body
            pages =
db(db.plugin_wiki_page.id>0).select(db.plugin_wiki_page.slug,db.plugin_wiki_page.body)
#how
to cache pages object?
            for page in pages:
                if page.body.find(string) > -1:
                    found.add(page.slug)

            #search in page body
            pages =
db(db.plugin_wiki_page.id>0).select(db.plugin_wiki_page.slug,db.plugin_wiki_page.title)
#how
to cache pages object?
            for page in pages:
                if page.title.find(string) > -1:
                    found.add(page.slug)

            #search in tags
            #TO-DO

            if found:
                return UL(*[LI(*[A(db(db.plugin_wiki_page.slug==row)\

 .select(db.plugin_wiki_page.title)[0].title,\

_href=URL(r=request,f='page',args=[row,]))])\
                                for row in found])
            else:
                return nfmessage % string

        else:
            return ''

2010/7/28 mdipierro <mdipie...@cs.depaul.edu>

> contains and startwith do not work on GAE because they do not support
> it. I am looking into possible workaround. Instead of this:
>
> pages =
> db(db.plugin_wiki_page.id>0).select(db.plugin_wiki_page.slug)
>            for page in pages:
>                if page.slug.find(string) > -1:
>                    found.add(page.slug)
>
> you can do this
>
> found =
> db(db.plugin_wiki_page.id>0).select(db.plugin_wiki_page.slug).find(lambda
> r: r.slug.find(string)>=0)
>
>
>
> On Jul 27, 10:34 pm, Bruno Rocha <rochacbr...@gmail.com> wrote:
> > I Solved my problem in a hard way with a custom widget, the only way I
> found
> > to perform %LIKE% on GAE
> >
> > @staticmethod
> >     def searchPages(string=None,nfmessage='Nothing found with %s'):
> >         """
> >         string: string to be found
> >         """
> >         found = set()
> >         if string:
> >             #search in slug
> >             pages =
> > db(db.plugin_wiki_page.id>0).select(db.plugin_wiki_page.slug)
> >             for page in pages:
> >                 if page.slug.find(string) > -1:
> >                     found.add(page.slug)
> >
> >         if found:
> >             return UL(*[LI(row) for row in found])
> >         else:
> >             return nfmessage % string
> >
> > 2010/7/28 Bruno Rocha <rochacbr...@gmail.com>
> >
> >
> >
> > > Also fails on JQGRID Search,
> > > I Know GAE has some limitations performing LIKE, so I think if this
> have no
> > > solution, may be disabled when running in GAE.
> >
> > > 2010/7/28 Bruno Rocha <rochacbr...@gmail.com>
> >
> > > Hi,
> >
> > >> trying to use the search widget on GAE i got an error,
> >
> > >> ``
> > >> name: search
> > >> table: plugin_wiki_page
> > >> ``:widget
> >
> > >> Only EQUALS and NOT EQUALS runs ok, when I try CONTAINS, STARTSWITH or
> > >> ENDSWITH I got the error:
> >
> > >> YOU CAN TRY HERE:
> > >>http://web2pybrasil.appspot.com/cursoweb2py/plugin_wiki/page/error-on.
> ..
> >
> > >> THE ERROR:
> > >> Traceback (most recent call last): File
> > >>
> "/base/data/home/apps/web2pybrasil/3.343537232039186008/applications/cursoweb2py/models/plugin_wiki.py",
> > >> line 555, in render_widget html =
> getattr(PluginWikiWidgets,name)(**args)
> > >> File
> > >>
> "/base/data/home/apps/web2pybrasil/3.343537232039186008/applications/cursoweb2py/models/plugin_wiki.py",
> > >> line 226, in search search, results = crud.search(db[table]) File
> > >>
> "/base/data/home/apps/web2pybrasil/3.343537232039186008/gluon/tools.py",
> > >> line 2979, in search query &= self.get_query(field, opval, value) File
> > >>
> "/base/data/home/apps/web2pybrasil/3.343537232039186008/gluon/contrib/gql.py",
> > >> line 569, in __and__ if other.filters[0].one(): AttributeError:
> 'Query'
> > >> object has no attribute 'filters'
> >
> > >> --
> >
> > >>http://rochacbruno.com.br
> >
> > > --
> >
> > >http://rochacbruno.com.br
> >
> > --
> >
> > http://rochacbruno.com.br
>



-- 

http://rochacbruno.com.br

Reply via email to