在地图字段中搜索
我正在使用吗啡。正如你所知,对于一个简单的搜索,我可以使用这个:
q.field("fieldname").containsIgnoreCase(texttosearch);
但我的字段类型是地图。所以我必须像这样更改它(使用点):
q.field("mapname.fieldname").containsIgnoreCase(texttosearch);
但我想再次在所有字段中搜索。我可以通过对所有字段重复操作来简单地做到这一点。问题是我的字段数不是静态的。 我该如何解决这个问题?
I'm using morphia. As u know for a simple search I can use this:
q.field("fieldname").containsIgnoreCase(texttosearch);
But my field type is map. So I must change it like this(use dot):
q.field("mapname.fieldname").containsIgnoreCase(texttosearch);
But again I want to search in all fields. I can simply do this by repeating for all fields. The problem is my field count is not static.
How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该将其存储为映射,而应存储为键/值对的数组/列表。然后你可以搜索关键字段,并对其建立索引。这不是吗啡目前为您做的事情,而是可以作为 Map 的替代存储格式。这将是一种非常不同的格式。
查看此讨论,了解更多背景
You should store it not as a map, but as an array/list of key/value pairs. Then you can search the key field, and index it. This is not something morphia does for you at the moment but something which could be an alternate storage format for Map. It would be a very different format.
Take a look at this discussion for more background