Updating SearchableModel entities

33 views
Skip to first unread message

Gareth

unread,
May 7, 2008, 5:27:57 AM5/7/08
to Google App Engine
Having created a SearchableModel entity, updating it doesn't seem to
update the full text index - Is that expected behaviour?

A little unit test to explain what I mean:

import sys, os, time
sys.path.append('/usr/local/google_appengine')
sys.path.append('/usr/local/google_appengine/lib/yaml/lib')

import unittest
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import datastore_file_stub
from google.appengine.api import mail_stub
from google.appengine.api import urlfetch_stub
from google.appengine.api import user_service_stub
from google.appengine.ext import db, search



APP_ID = u'test'
AUTH_DOMAIN = 'gmail.com'
LOGGED_IN_USER = 'te...@example.com'

class Searchable(search.SearchableModel):
searchtext = db.TextProperty()


class TestSearch(unittest.TestCase):

def setUp(self):
# Ensure we're in UTC.
os.environ['TZ'] = 'UTC'
time.tzset()

# Start with a fresh api proxy.
apiproxy_stub_map.apiproxy =
apiproxy_stub_map.APIProxyStubMap()

# Use a fresh stub datastore.
stub = datastore_file_stub.DatastoreFileStub(APP_ID, '/dev/
null', '/dev/null')
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)

# Use a fresh stub UserService.
apiproxy_stub_map.apiproxy.RegisterStub(
'user', user_service_stub.UserServiceStub())
os.environ['AUTH_DOMAIN'] = AUTH_DOMAIN
os.environ['USER_EMAIL'] = LOGGED_IN_USER

# Use a fresh urlfetch stub.
apiproxy_stub_map.apiproxy.RegisterStub(
'urlfetch', urlfetch_stub.URLFetchServiceStub())

# Use a fresh mail stub.
apiproxy_stub_map.apiproxy.RegisterStub(
'mail', mail_stub.MailServiceStub())

def testUpdate(self):
# create an entity
s = Searchable(searchtext='Test Entry One')
s.put()
id = s.key().id()

# make sure we can find it by search
result = Searchable.all().search('one')
self.assertEquals(1, result.count())

# reload the entity directly from the db
s = Searchable.get_by_id(id)
self.assertEquals('Test Entry One', s.searchtext)

# update the search text and re-save it
s.searchtext = 'Test Entry Updated'
s.put()

# shouldn't be any entries with 'one' in them now
result = Searchable.all().search('one')
self.assertEquals(0, result.count())

# should be able to find our updated entry though
result = Searchable.all().search('updated')
self.assertEquals(1, result.count())

if __name__ == '__main__':
unittest.main()

Chenjie

unread,
May 9, 2008, 2:29:57 AM5/9/08
to Google App Engine
Yes, it likes a bug, I encountered the same issue.

BTW, how to do GQL query on SearchableModels? I mean write the GQL
query string not use the SearchableQuery.
It looks like GAE automatically create a ListProperty field
__searchable_text_index, so can we write query string like 'select *
from Searchable where __searchable_text_index=1:'?

Gareth

unread,
May 9, 2008, 2:05:36 PM5/9/08
to Google App Engine
Opened issue 337 if you care to star


On May 8, 11:29 pm, Chenjie <chenyue...@gmail.com> wrote:
> Yes, it likes a bug, I encountered the same issue.
>
> BTW, how to do GQL query on SearchableModels? I mean write the GQL
> query string not use the SearchableQuery.
> It looks like GAE automatically create a ListProperty field
> __searchable_text_index, so can we write query string like 'select *
> from Searchable where __searchable_text_index=1:'?
>
> Gareth wrote:
> > Having created aSearchableModelentity, updating it doesn't seem to
> > update the full text index - Is that expected behaviour?
>
> > A little unit test to explain what I mean:
>
> > import sys, os, time
> > sys.path.append('/usr/local/google_appengine')
> > sys.path.append('/usr/local/google_appengine/lib/yaml/lib')
>
> > import unittest
> > from google.appengine.api import apiproxy_stub_map
> > from google.appengine.api import datastore_file_stub
> > from google.appengine.api import mail_stub
> > from google.appengine.api import urlfetch_stub
> > from google.appengine.api import user_service_stub
> > from google.appengine.ext import db, search
>
> > APP_ID = u'test'
> > AUTH_DOMAIN = 'gmail.com'
> > LOGGED_IN_USER = 't...@example.com'

Aral Balkan

unread,
Jun 17, 2008, 10:49:27 AM6/17/08
to Google App Engine
Thanks for opening the issue, Gareth. I'm running into this too.

Aral

On May 9, 7:05 pm, Gareth <gwa...@gmail.com> wrote:
> Opened issue 337 if you care to star
<snip>

tijer

unread,
Jul 6, 2008, 12:37:34 PM7/6/08
to Google App Engine
Ya, same issue.

First I thought it was because you're using put() and not save() in
your code, but save() has same result - index is not rebuild.

:(

ajbro...@googlemail.com

unread,
Jul 21, 2008, 12:00:30 PM7/21/08
to Google App Engine
Same again. I am now deleting the data using db.delete(myData) and
saving a new copy back. Nasty but gets around my evaluation problems
for now.
> > <snip>- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages