Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-26-2022 08:53 PM
Let me explain it very clearly.
I have a graph structure in neo4j which contains head nodes, tail nodes and relationship.
Apart from head, tail nodes, i have a main node which connects all head nodes.
so it look like this..
As you can see in above picture, handbook is the main node and whichever node is connected with handbook is the head node and whichever node is connnected with head node is tail node.
So i want to write a query to search some keyword like 'safe design' | 'safety in design' and it should return me the main node (handbook)
what would be the search query for this?
Solved! Go to Solution.
01-02-2023 07:03 AM
Try this:
match(entity:Entity{name: "constructible"})
match(entity)<-[*0..1]-(:Entity)-[:HAS_MAIN]->(main)
return main
limit 1
12-27-2022 02:18 AM
Where are the keywords stored? Do you have a working query that search keywords? What kind of string search do you want to use, something like “keyword contains search criteria”, do you want to use the full-text searching feature?
12-27-2022 02:21 AM
hi, @glilienfield
keyword = i meant the node name,
assume that there is a node called 'safety design', i want to search that node name safety design via cypher query language and it should return me the main node (which is handbook)
similarly if im searching for other node like 'risks' then it should return me the main node because main node is linked to all other head nodes
12-27-2022 05:56 AM
Your data model from your other post is:
(tail:Entity)<-[]-(head:Entity)-[:HAS_MAIN]->(main:Entity)
If your search by name results in a tail node, then the match pattern to get the main node is the following:
(tail)<-[]-(:Entity)-[:HAS_MAIN]->(main:Entity)
if your search results in a head node, then your match pattern to find the main nodes:
(head)-[:HAS_MAIN]->(main:Entity)
the only difference if the first node and relationship, so you can use a variable length relation of 0..1 to account for both cases. The following should work:
match(entity:Entity{name:$name})
match(entity)<-[*0..1]-(:Entity)-[:HAS_MAIN]->(main)
return main
limit 1
I added the ‘limit 1’ because it is possible from your data that there could be multiple paths back to the single ‘main’ node.
12-27-2022 08:02 PM
01-01-2023 07:42 PM
Hi @glilienfield , Happy New year.
I have typed your cypher query but I'm getting this error, could u pls check what mistake i did?
I have a head node called 'risk', i want to find the main node relation from the head node so i typed this query
match(entity:Entity{risk:$risk})
match(entity)<-[*0..1]-(:Entity)-[:HAS_MAIN]->(main)
return main
limit 1
but im getting error, pls have a look
01-01-2023 08:37 PM
You have a parameter in the query named ‘risks’. It is referenced by ‘$risks’ It’s value needs to be defined, which you can do with
:param risks => “high”
where you would substitute ‘high’ with your value for risks. This value will be passed to the query when executed.
01-02-2023 03:42 AM
Variables prefixed with ‘$’ are considered parameters. Their value needs to be defined, and the value will be substituted during execution. Read below reference on parameters in neo4j desktop.
https://neo4j.com/docs/browser-manual/current/operations/query-parameters/
you can also replace the parameter with the value if you want to avoid using a parameter. Assuming the value of risk for the head node is “high”, the query would look like this. Replace “high” with your actual value.
match(entity:Entity{risk:”high”})
match(entity)<-[*0..1]-(:Entity)-[:HAS_MAIN]->(main)
return main
limit 1
01-02-2023 04:57 AM
check this out.
'document' is the main node name
i have a node called maintainable
if i search for maintainable then it should return me document main node but when i run this code im getting,
01-02-2023 02:32 AM
@glilienfield the query seems complicated to me.
Can you send me the query for searching using full search index of my previous scenario?
01-02-2023 03:48 AM
The query should do what you want. It needs to deal with the fact traversing to the main node may require going through one or two nodes, either a head node or both a tail and head node.
what is your previous scenario?
01-02-2023 07:03 AM
Try this:
match(entity:Entity{name: "constructible"})
match(entity)<-[*0..1]-(:Entity)-[:HAS_MAIN]->(main)
return main
limit 1
All the sessions of the conference are now available online