How to make case insensitive filter queries with Google App Engine?

 ̄綄美尐妖づ 提交于 2019-12-28 04:23:13

问题


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.


回答1:


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.)




回答2:


An alternative solution to this problem - where the datasets are small - is to filter the results in python after you have called them from the datastore:

for each_item in list_of_results:
    if each_item.name.lower().rfind(your_search_term) != -1:
        #Your results action


来源:https://stackoverflow.com/questions/3289781/how-to-make-case-insensitive-filter-queries-with-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!