自秋季更新后,GAE 现在支持部分搜索。根据文档:“API 支持字符串字段的部分文本匹配”。
根据许多线程,这似乎是一个非常受欢迎的请求: Partial matching GAE search API Does GAE Datastore support 'partial text search'?
所以我假设搜索“pyt”现在会返回“python”
有没有人让这个工作?对我不起作用。我很好奇是否需要一些设置,例如用于词干提取的 ~。
最佳答案
https://cloud.google.com/appengine/docs/python/search/ 中的“API 支持字符串字段的部分文本匹配”指的是通过标记匹配。具体见https://cloud.google.com/appengine/docs/python/search/#Python_Tokenizing_string_fields ...:
The string is split into tokens wherever whitespace or special characters (punctuation marks, hash sign, etc.) appear. The index will include an entry for each token. This enables you to search for keywords and phrases comprising only part of a field's value.
因此你的假设:
So I would assume a search for 'pyt' would now return 'python'
是没有根据的——“部分搜索”是指文档的部分(文本字段中标记的子集),不是 每个标记的部分(这会导致组合爆炸,例如单个标记 python
必须作为每个条目进行索引:
p
py
pyt
pyth
pytho
python
y
yt
yth
ytho
ython
t
th
tho
thon
h
ho
hon
o
on
n
如果您想要,很容易编写自己的代码来产生爆炸(产生一个伪文档,其中包含来自真实起始文档的所有这些子字符串)——但是,对于任何非常重要的起始文档,您很可能最终要么为荒谬的资源付费,要么达到绝对最大配额的硬性上限。
提示:如果您在网络上搜索“pyt”,您会找到包含“python”的文档吗?试试——前者有 1000 万次点击(半岛青年剧院、Michael Jackson 的 P.Y.T.(漂亮年轻的东西)等),后者有 1.8 亿次点击(语言、蛇、喜剧组:-)。
关于python - GAE Search API 现在支持部分搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21222102/