简体   繁体   English

Neo4j gem-从数组对象查询

[英]Neo4j gem - Querying from an array object

In my previous example I had this query 在上一个示例中,我有此查询

current_user.friends.events(:event, :rel).where("rel.admin = {admin_p} AND event.detail = {detail_p}").params(admin_p: true, detail_p: true).pluck(:event)

current_user.friends.events brings me up to events to continue my chain, but does this work for if I already have an object that contains an array of events? current_user.friends.events使我进入事件,以继续我的链,但是,如果我已经有一个包含事件数组的对象,这对我有用吗?

In my example, I am trying to use geocoder to pull in proximity. 在我的示例中,我尝试使用Geocoder拉近距离。

So I have my user and events which are geocoded. 因此,我已经对用户和事件进行了地理编码。

Geocoder can do something like this Geocoder可以做这样的事情

Venue.near([40.71, 100.23], 20) # find all objs within 20 miles Venue.near([40.71, 100.23], 20) #查找20英里内的所有Venue.near([40.71, 100.23], 20)

So I can essentially find all the events and store it in an object. 因此,我基本上可以找到所有事件并将其存储在一个对象中。 Now can I use the neo4j query to filter that object? 现在可以使用neo4j查询来过滤该对象吗?

eg 例如

array_object(:event, :rel).where("rel.admin = {admin_p} AND event.detail = {detail_p}").params(admin_p: true, detail_p: true).pluck(:event)

Even if this works, is there an alternate way to do this? 即使这可行,还有其他方法可以做到吗?

You can't call query proxy methods on an array, so just grab the IDs of those events and filter your match accordingly. 您不能在数组上调用查询代理方法,因此只需获取这些事件的ID并相应地过滤匹配项即可。

current_user.friends.events(:e).where(neo_id: array_object.map { |e| e.neo_id })

That'll filter the user's friends' events that are in that array. 这将过滤该数组中用户的朋友的事件。 We can use neo_id in where for better performance. 我们可以在where使用neo_id以获得更好的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM