what is the best filter to query a full name datas

2019-03-02 06:49发布

I have this datastore model:

class Person(db.Model):
    person_name = db.StringProperty(required = True)        
    nacionality = db.StringProperty(required = True)
    marital_status = db.StringProperty(required = True)
    profession = db.StringProperty(required = True)
    SSN = db.IntegerProperty(required = True)
    driver_license = db.IntegerProperty(required = True)
    address = db.PostalAddressProperty(required = True)

In this Model, person_name could be something like this: 'Carl Sagan' (there is only on property for the entiry name). But when I query it, this way:

    searched_name = 'Carl'
    p = Person.all()
    persons = p.filter('person_name >=', searched_name)

I got, as a result, names which doesn't begin with 'Carl' or neither have 'Carl' in any part of the name. If I query this way: persons = p.filter('person_name >=', searched_name) I got none result (even 'Carl Sagan' isn't found). So, I'd like to know: what is the best filter to this kind of query? (quering a complete name property using only the first name)?

1条回答
霸刀☆藐视天下
2楼-- · 2019-03-02 07:03

String filter works as it was comparing chars starting beginning of string. You can do something like this:

p.filter('person_name >=', searched_name)
p.filter('person_name <', searched_name + u'\ufffd')
查看更多
登录 后发表回答