javascript - 搜索 API : How come "Ondřej" matches "ondrej"? 我需要在浏览器中模仿它

标签 javascript google-app-engine search google-cloud-datastore gae-search

更新:最后我使用 Java6 Normalizer 来找出哪些字符是 a-zA-Z 的扩展。所以现在所有奇怪的字符都被翻译成这 50 个 ASCII 字母。打字/自动完成时没有明显减慢。

<小时/>

GAE 搜索 API 使用什么算法处理字符串?

出于优化目的(在浏览器内),我需要模仿在与索引匹配之前对“needle”字符串进行的任何处理。 基本上,它意味着将“奇怪”的字符翻译成“无聊”(和小写)的表示形式:

  • ř,Ř => r
  • ě,é,ë,Ě,É,Ë => e
  • ...

是否有一些标准化(或至少“众所周知”)的翻译表,这样我就不会错过一些字符?

最佳答案

使用unidecode python 库。

>>> import unidecode
>>> unidecode.unidecode(u'ř')
'r'
>>> unidecode.unidecode(u'ě,é,ë,Ě,É,Ë')
'e,e,e,E,E,E'
>>> unidecode.unidecode(u'ě,é,ë,Ě,É,Ë').lower()
'e,e,e,e,e,e'

关于javascript - 搜索 API : How come "Ondřej" matches "ondrej"? 我需要在浏览器中模仿它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27739210/

相关文章:

javascript - JSON 成功时用字符串回复函数

javascript - path.getTotalLength 适用于文本 svg 吗?

javascript - 使用 JavaScript 如何捕获所有 XMLHttpRequest onreadystatechange?

javascript - 如何通过过渡打开/关闭文本?

google-app-engine - 无法为 eclipse (indigo) 安装 google app engine 插件

python - NDB 中 SelfReferenceProperty 的等价物

java - AppEngine 下载图

Python:在文件中搜索字符串

java - 在java中搜索二维数组中的一系列值

Java/Lucene 在多个字段中搜索子字符串