Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6005651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:25:39+00:00 2026-05-23T01:25:39+00:00

I’m developing a simple Blogging/Bookmarking platform and I’m trying to add a tags-explorer/drill-down feature

  • 0

I’m developing a simple Blogging/Bookmarking platform and I’m trying to add a tags-explorer/drill-down feature a là delicious to allow users to filter the posts specifying a list of specific tags.

Something like this:
enter image description here

Posts are represented in the datastore with this simplified model:

class Post(db.Model):
    title = db.StringProperty(required = True)
    link = db.LinkProperty(required = True)
    description = db.StringProperty(required = True)
    tags = db.ListProperty(str)
    created = db.DateTimeProperty(required = True, auto_now_add = True)

Post’s tags are stored in a ListProperty and, in order to retrieve the list of posts tagged with a specific list of tags, the Post model exposes the following static method:

@staticmethod
def get_posts(limit, offset, tags_filter = []):
        posts = Post.all()
        for tag in tags_filter:
          if tag:
              posts.filter('tags', tag)
        return posts.fetch(limit = limit, offset = offset)

This works well, although I’ve not stressed it too much.

The problem raises when I try to add a “sorting” order to the get_posts method to keep the result ordered by "-created" date:

@staticmethod
def get_posts(limit, offset, tags_filter = []):
        posts = Post.all()
        for tag in tags_filter:
          if tag:
              posts.filter('tags', tag)
        posts.order("-created")
        return posts.fetch(limit = limit, offset = offset)

The sorting order adds an index for each tag to filter, leading to the dreaded exploding indexes problem.
One last thing that makes this thing more complicated is that the get_posts method should provide some pagination mechanism.

Do you know any Strategy/Idea/Workaround/Hack to solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:25:39+00:00Added an answer on May 23, 2026 at 1:25 am

    Queries involving keys use indexes
    just like queries involving
    properties. Queries on keys require
    custom indexes in the same cases as
    with properties, with a couple of
    exceptions: inequality filters or an
    ascending sort order on key do not
    require a custom index, but a
    descending sort order on
    Entity.KEY_RESERVED_PROPERTY_key_
    does.

    So use a sortable date string for the primary key of the entity:

    class Post(db.Model):
        title = db.StringProperty(required = True)
        link = db.LinkProperty(required = True)
        description = db.StringProperty(required = True)
        tags = db.ListProperty(str)
        created = db.DateTimeProperty(required = True, auto_now_add = True)
    
        @classmethod
        def create(*args, **kw):
             kw.update(dict(key_name=inverse_millisecond_str() + disambig_chars()))
             return Post(*args, **kw)
    

    …

    def inverse_microsecond_str(): #gives string of 8 characters from ascii 23 to 'z' which sorts in reverse temporal order
        t = datetime.datetime.now()
        inv_us = int(1e16 - (time.mktime(t.timetuple()) * 1e6 + t.microsecond)) #no y2k for >100 yrs
        base_100_chars = []
        while inv_us:
            digit, inv_us = inv_us % 100, inv_us / 100
            base_100_str = [chr(23 + digit)] + base_100_chars
        return "".join(base_100_chars)
    

    Now, you don’t even have to include a sort order in your queries, although it won’t hurt to explicitly sort by key.

    Things to remember:

    • This won’t work unless you use the “create” here for all your Posts.
    • You’ll have to migrate old data
    • No ancestors allowed.
    • The key is stored once per index, so it is worthwhile to keep it short; that’s why I’m doing the base-100 encoding above.
    • This is not 100% reliable because of the possibility of key collisions. The above code, without disambig_chars, nominally gives reliability of the number of microseconds between transactions, so if you had 10 posts per second at peak times, it would fail 1/100,000. However, I’d shave off a couple orders of magnitude for possible app engine clock tick issues, so I’d actually only trust it for 1/1000. If that’s not good enough, add disambig_chars; and if you need 100% reliability, then you probably shouldn’t be on app engine, but I guess you could include logic to handle key collisions on save().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.