Neo4j gem - Querying multiple parameters in one property

128 Views Asked by At

I'm not even sure if this title is the best description.

I'm building some basic filtering capabilities via a form for my events. Events have a category from a select drop down.

Now when you want to filter, you can select via checkboxes the categories you want to display.

I'm a bit stumped how to do that. Is it possible to do it all in one query? Or do you separate it into 1 for each category?

My old query was this 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)

In this case, I would need something like event.category = category1, category2, cateogry3 . Obviously this isn't how it's written. Ways to achieve this?

1

There are 1 best solutions below

1
On BEST ANSWER

In cypher, IN lets you match results within an array.

MATCH (u:User)-[r1:INVITED_TO]->(e:Event) WHERE e.uuid IN [1, 2, 3, 4, 5] RETURN e

That would match events with any of the uuid properties in that array. In the Ruby gem, this is handled automatically for you in QueryProxy if you use an array in a where method.

current_user.events.where(category: [1, 2, 3, 4, 5])

In your form, ensure that each checkbox's value corresponds with its ID. Put those IDs into an array and search as demonstrated above.