Hi,

So I'm building an input field in my app that will give suggestions as
a user types with things the user has previously entered. The strings
will be relatively short (<25 characters probably), and I'd like to
match any substring, e.g. typing "sa" might bring up "John Sanderson"
as well as "Sam Smith."

I've implemented it a certain way, and I'm looking for thoughts/
suggestions/potential failings of the implementation if you have some
time to take a look.

Right now, I have two db.Models:

class NameIndex(db.Model):
  index        = db.StringProperty()
  names      = db.StringListProperty()

class Name(db.Model):
  name           = db.StringProperty()
  last_used_at = db.DateTimeProperty(auto_now_add=True)

When a name is entered, I check to see if an existing Name entity
exists and simply update the last_used_at field if so. If not, I add
the Name and also add NameIndex entries, one entry for the substring
starting at every character position in the string to the end of the
string:

"John Smith" becomes:

johnsmith
ohnsmith
hnsmith
nsmith
...
etc., each with a property pointing back to "John Smith" (and other
matching entries if two full names have the same indexed substring).

Then, as a user types, I take the substring and look for NameIndex
entries where index >= :substring and index < :substring + 'zzzz ...',
which accurately returns the entries with a matching substring.

I have a couple of questions about this approach:

- Will this create too many entities? Is this something to worry
about?
- Is writing len(str) entries to the datastore with every new name
going to be a problem?
- Is there a better way?

Thanks for reading,

Taylor Hughes
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to