3 questions (about paging again)

2 views
Skip to first unread message

lookon

unread,
Dec 7, 2008, 9:51:44 PM12/7/08
to Google App Engine
I've got how to page to some extent..But I still have some problems

1.What's the best way to implement tag to a model

2.in this way, how to page the tag page?

for example, http://a.appspot.com/tag/google, I need to show all model
whose tag is google, and I need to page it...

3.How to page the search result?
If I search Google, I will get all the result, and I don't know how to
page them.

Thanks.

Marzia Niccolai

unread,
Dec 8, 2008, 3:03:02 PM12/8/08
to google-a...@googlegroups.com
Hi,

If you store the tags in a list, you should be able filter on that list using a simple equals filter, something like:

MyProperty.all().filter('my tags =', tag).filter('index <=', starting_index).fetch(10)

Assuming you don't have a large number of tags (a couple per entry), this shouldn't result in an exploding index.

The third question, if I interpret it correctly, is about using the Google Search AJAX API? If you want to use the search API for your site, and page through the results on your site, it seems you can do pagination with their API, the docs are available here:
http://code.google.com/apis/ajaxsearch/documentation/reference.html#_class_GSearch

-Marzia

kang

unread,
Dec 8, 2008, 8:01:24 PM12/8/08
to google-a...@googlegroups.com
I haven't got it...what is the 'index' for in your code? For different tags, they have different index for an object.

3rd question is about search the model. 
--
Stay hungry,Stay foolish.

Marzia Niccolai

unread,
Dec 9, 2008, 12:25:11 PM12/9/08
to google-a...@googlegroups.com
Hi,

By index I mean whatever index you are using for pagination, an integer property as described in the building scalable web applications talk:
http://sites.google.com/site/io/building-scalable-web-applications-with-google-app-engine

This should work to page searchable entities as well. Simply search for a specific term, and then filter on the paging index.

-Marzia

kang

unread,
Dec 9, 2008, 9:41:14 PM12/9/08
to google-a...@googlegroups.com
I've watched the video...my question is how to make paging index for tag and term for search?
--
Stay hungry,Stay foolish.

Marzia Niccolai

unread,
Dec 10, 2008, 12:17:19 PM12/10/08
to google-a...@googlegroups.com
Hi,

There is no difference.  In addition to the index for paging, you just have a tag property.  So

# or SearchableModel
class MyProperty(db.Model):
  # For paging
  index = db.IntegerProperty()
  my_tags = db.StringListProperty()

For the first page, you do a fetch like this:
results = MyProperty.all().filter('my_tags =', tag).order('-index').fetch(11)

if len(results) == 11:
  next_page = results[10].index

So the next page you would fetch /tag/my_tag?start=[next_page]

And the query for this would be:

results = MyProperty.all().filter('my_tags =', tag).filter('index <=', next_page)order('-index').fetch(11)

if len(results) == 11:
  next_page = results[10].index

All adding tags does is introduce an additional property to filter on, along with the index for paging.

-Marzia
Reply all
Reply to author
Forward
0 new messages