views:

82

answers:

1

Hi All,

I am working on a GAE Django Project where I have to implementing the search functionality, I have written a query and it fetches the data according to the search keyword.

portfolio = Portfolio.all().filter('full_name >=',key).filter('full_name <',unicode(key) + u'\ufffd')

The issue with this query is, that it is case sensitive.

Is there any way through which I can make it to work, without depending upon the case of the keyword?

Please suggest.

Thanks in advance.

+8  A: 

You need to store normalized versions of your data at write time, then use the same normalization to search.

Store the data either all uppercase or all lowercase, optionally removing punctuation and changing all whitespace to a single space and maybe converting non-ASCII characters to some reasonable ASCII representation (which is, of course, trickier than it sounds.)

Wooble
Thanks for you answer Wooble. But the project is a maintenance project and so already has lots of data which is being used by lots of pages. Making changes to the data now would require a good amount of effort i.e. making changes to all the views where the data is being rendered. Isn't there any way to make it work with the current structure?
anand
You wouldn't necessarily have to make changes to all the views, etc. Just add a field called foo_uppercase, and have a task go over all your entities 1000 at a time or something and fill in the field.
Jason Hall
@Jason thanks for your reply. But even then it will require to change change all the existing datastore values for this property to be changed in either lower or uppercase?
anand
Well I had to do what Wooble has suggested. But I think there should be some way to make the case insensitive filtering. Please let me know.
anand
@anand I don't think anybody's talking about changing the existing value, just creating a *new* field and populating it with the upper/lowercase version, then searching over that.
Jason Hall
@Jason yes, I have done the same. What I am not able to understand is, whats so different in google datastore that we are not able to make a case insensitive query. I understand being non-relational it has some limitations but this one I am not able to get.
anand
@anand Are case insensitive queries possible in standard SQL? It probably comes down to the fact that making the queries case insensitive would mean slower reads on all queries, whether or not you cared about sensitivity, or at least a modification of the API, which would invariably displease some set of developers who do/don't want sensitivity by default. And when there's an easy enough workaround that generalizes well, why bother building it into the datastore itself?
Jason Hall