memgraph / gqlalchemy

GQLAlchemy is a library developed with the purpose of assisting in writing and running queries on Memgraph. GQLAlchemy supports high-level connection to Memgraph as well as modular query builder.
https://pypi.org/project/gqlalchemy/
Apache License 2.0
227 stars 32 forks source link

STRING-specific comparison operators #314

Open TheMrguiller opened 4 months ago

TheMrguiller commented 4 months ago

Hi,

I am new to memgraph and i have observe that there is not documentation on how to use string-specific comparison operators. I have tried the following. but with no success:

results = list(
                    match()
                    .node(labels="Organizations", variable="o")
                    .where(item="o.name",operator="CONTAINS",literal=organization["name"])
                    .return_()
                    .execute()
                )

¿Is there any work arounds?

katarinasupe commented 4 months ago

Hi @TheMrguiller and thank you for opening this issue. contains() is a function in Memgraph, which we use like this in a Cypher query:

contains(string: string, substring: string) -> (boolean)

We didn't implement a wrapper around this for now, so to do that, you should run smth similar to following query as a workaround:

results = list(
                    match()
                    .node(labels="Organizations", variable="o")
                    .add_custom_cypher("WHERE contains(o.name, " +  organization["name"] + ")")
                    .return_()
                    .execute()
                )

Just tweak/escape the quotes in organization name if needed.

I will leave this issue opened because we should implement functions in the query builder.

TheMrguiller commented 4 months ago

Hi @katarinasupe ,

Thank you so much for your response. In the case of wanting to add operators like STARTS WITH and ENDS WITH, could we do in the same way?

katarinasupe commented 4 months ago

Yes @TheMrguiller, you do the same for all functions. Here are the string ones - https://memgraph.com/docs/querying/functions#string-functions. For example, STARTS WITH and ENDS WITH are startsWith and endsWith.

What are you working on? Can you tell me more about the use case?

TheMrguiller commented 4 months ago

Yes, we are conducting a proof of concept for using Memgraph with Langchain, and we have encountered documents with errors in them. For instance, some names of people are not fully specified or company names are missing their original S.A. designation. Since we don't have the exact, error-free strings, we are aiming to minimize duplicates by utilizing the 'contains' and 'startswith' operators.

katarinasupe commented 4 months ago

@TheMrguiller I get it! Sounds like a cool use case. Keep me posted on how the PoC goes, I would love to get your feedback on Memgraph. If you will need more help, feel free to schedule an office hours call and join our Discord server where you can ask various questions about Memgraph.