[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q object filter() for connected nodes #535

Open
zacharymostowsky opened this issue Dec 7, 2020 · 5 comments
Open

Q object filter() for connected nodes #535

zacharymostowsky opened this issue Dec 7, 2020 · 5 comments

Comments

@zacharymostowsky
Copy link
zacharymostowsky commented Dec 7, 2020

Hi,

I am trying to use a Q object search to lookup a user's following by firstName and lastName. Is this not supported?

class NeoUser(StructuredNode):
    firstName = StringProperty()
    lastName = StringProperty()
    following = RelationshipTo('NeoUser', 'IS_FOLLOWING')

I receive error that filter() function can take only 1 positional argument.

userFollowing = neoUser.following.filter(Q(firstName__icontains=filterText) | Q(lastName__icontains=filterText))

Note, I can use the Q object filter directly on the NeoUser queryset like below.

userFollowing = NeoUser.nodes.filter(Q(firstName__icontains=filterText) | Q(lastName__icontains=filterText))

Thanks in advance. Love the library.

@yantraupesh
Copy link

Thank you for the amazing library!

I'm having the same problem. Is this going to be supported in future?

For a simple query as following either one needs to apply plain cypher or run offline for loops to search.

Query-> Find me a patient who is registered in hospitals of given names. Just like @zacharymostowsky I would write the query as patient.registered_with.filter(Q(hospital_name__icontains='X') | Q(hospital_name__icontains='Y'))

@zacharymostowsky
Copy link
Author

I haven’t seen any update. I’m not that confident to put in a PR by myself to fix this but happy to pair on it. In the meantime I wrote a custom cypher query and inflated my model objects to produce the desired result. Hope this helps. Let me know if you want to tak anything through.

@yantraupesh
Copy link

@zacharymostowsky Can you share your workaround please. I'm new to neo and struggling.

@zacharymostowsky
Copy link
Author

Sure np, this is a query I wrote to essentially search a users followers by first and last name. Optionally you can add it this as a method to your NeoModel StructuredNode and reference the class with self instead. Hope this helps. Here is relevant docs.

query = '''
              MATCH (u:NeoUser {userId:$userId})-[:HAS_FOLLOWERS]-(f:NeoUser) 
              WHERE toLower(f.firstName) CONTAINS $filterText 
              OR toLower(f.lastName) CONTAINS $filterText 
              RETURN DISTINCT f
              ORDER BY f.firstName DESC LIMIT $limit
              '''
params = {"userId": userId, "filterText": filterText.lower(), "limit": limit}
results, meta = db.cypher_query(query, params)
myNeoUserNodes =  [NeoUser.inflate(row[0]) for row in results]

@aanastasiou
Copy link
Collaborator

@zacharymostowsky @yantraupesh Thanks for this note but I am just wondering if this has something to do with the way you are trying to use this functionality. See here for example. Let me know if this works, sorry for the late reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants