Google App Engine 和 SQL LIKE
有没有办法使用类似于 SQL LIKE 语句的过滤器来查询 GAE 数据存储?例如,如果一个类有一个字符串字段,并且我想查找该字符串中具有某些特定关键字的所有类,我该怎么做? 看起来 JDOQL 的 matches() 不起作用......我错过了什么吗?
欢迎任何评论、链接或代码片段
Is there any way to query GAE datastore with filter similar to SQL LIKE statement? For example, if a class has a string field, and I want to find all classes that have some specific keyword in that string, how can I do that?
It looks like JDOQL's matches() don't work... Am I missing something?
Any comments, links or code fragments are welcome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 GAE/J 文档所说,BigTable 没有这样的本机支持。您可以使用JDOQL String.matches 来表示“something%”(即startsWith)。仅此而已。否则在内存中对其进行评估。
As the GAE/J docs say, BigTable doesn't have such native support. You can use JDOQL String.matches for "something%" (i.e startsWith). That's all there is. Evaluate it in-memory otherwise.
如果您有很多项目需要检查,您希望完全避免加载它们。最好的方法可能是在写入时分解输入。如果您仅按整个单词进行搜索,那么这很容易,
例如,“Hello world”变为“Hello”、“world” - 只需将两者添加到多值属性中即可。如果您有大量文本,则希望避免加载多值属性,因为您只需要它来进行索引查找。您可以通过创建“关系索引实体”来完成此操作 - 有关详细信息,请参阅 Bret slatkins Google IO 演讲。
您可能还想将输入分解为 3 个字符、4 个字符等字符串或对单词进行词干 - 也许使用 lucene 词干分析器。
If you have a lot of items to examine you want to avoid loading them at all. The best way would probably be to break down the inputs a write time. If you are only searching by whole words then that is easy
For example, "Hello world" becomes "Hello", "world" - just add both to a multi valued property. If you have a lot of text you want to avoid loading the multi valued property because you only need it for the index lookup. You can do this by creating a "Relation Index Entity" - see bret slatkins Google IO talk for details.
You may also want to break down the input into 3 character, 4 character etc strings or stem the words - perhaps with a lucene stemmer.