You can also do:

def keywords(record):
     return list(set(x.lower() for re.compile('\w
+').findall(record.content or '')))

db.define_table('posts',
                  Field('id', 'id'),
                  Field('content', 'text'),
                  Field('keywords',
'list:string',compute=keywords,writable=False,readable=False),
                  migrate=True)

def search_by_keywords(keywords):
      if not instance(keywords,list): keywords=keywords.split()
      query=reduce(lambda a,b:a&b,
[db.posts.keywords.contains(key.strip().lower()) for key in keywords])
      return db(query).select(db.posts.ALL)

Note db.Field is old syntax and deprecated. You can safely use Field
everywhere.

On Sep 6, 5:55 am, "Martin.Mulone" <[email protected]> wrote:
> DONT PAY ATTENTION TO THE EARLY POST WAS MISTAKEN SUBMMITED
>
> This is not a proper full text but i want to make a better search
> cause in gae don't have like operator, so i use new introduce
> list:string that is supported in both gae and sqlite. So in the
> search
> I use contains in that field, but at the moment there are a bug in
> web2pyhttp://code.google.com/p/web2py/issues/detail?id=105
>
> For example i have:
> db.define_table('posts',
>                   db.Field('id', 'id'),
>                   db.Field('content', 'text'),
>                   db.Field('keywords', 'list:string'), #tags
>                   db.Field('fulltext', 'list:string'),
>                   migrate=True)
>
> When i want to process content of text
>
> I use
>
> clean_words = get_clean_words(searchable)
> post.update_record(content= value, fulltext = clean_words)
>
> To search i Use contains().
>
> This remove the stop words of the text and save in a list string.
>
> http://code.google.com/p/instant-press/source/browse/trunk/models/ful...
>
> If you have a better ideas i am listening :)
>
> On 6 sep, 07:45, "Martin.Mulone" <[email protected]> wrote:
>
> > This is not a proper full text but i want to make a better search
> > cause in gae don't have like operator, so i use new introduce
> > list:string that is supported in both gae and sqlite. So in the search
> > I use contains in that field, but at the moment there are a bug in
> > web2pyhttp://code.google.com/p/web2py/issues/detail?id=105
>
> > For example i have:
>
> > db.define_table('posts',
> >                   db.Field('id', 'id'),
>
> >                   db.Field('keywords', 'list:string'),
> > #tags
> >                   db.Field('fulltext',
> > 'list:string'),
> >                   migrate=True)
>
> >http://code.google.com/p/instant-press/source/browse/trunk/models/ful...
>
> > On 5 sep, 13:53, John <[email protected]> wrote:
>
> > > Hi all.
> > > I'm newby in web2py.
> > >  How to  implement full text search in my web2py web application?
> > >   I am a big fan of the Xapian search engine library. Any plugin,
> > > recipes  suggestion ?
> > >  Thanks ,
> > >   John

Reply via email to