I am returning an extra line whereby the result is null and I dont know what is causing it. I have attached my query and result below. Thanks in advance.
CALL db.index.fulltext.queryNodes('livesearch', '*t*')
YIELD node
OPTIONAL MATCH (group:Group)-[:GROUPS]->(asset:Asset)<-[:ON]-(:Deploy)<-[:SCHEDULED]-(d:Device)
WHERE asset.asset_id = node.asset_id
WITH DISTINCT collect(d{.sigfox_id,asset,group}) as assetdata,node
OPTIONAL MATCH (gg:Group)-[:GROUPS]->(ga:Asset)<-[:ON]-(:Deployment)<-[:SCHEDULED]-(gd:Device)
WHERE gg.group_id = node.group_id
RETURN DISTINCT gg as groupdata, assetdata
Basically i need 2 list that is returned from the search (1. assets 2. asset groups) but in the asset list I require the device and the asset group properties returned also
Yes, I want to search Asset and Group nodes only. However my results show that I am getting extra results. As you can see in the above images, when I run my old query I only get 2 results, however, I am getting more results when I run yours.
Based on the results I get, it seems like it only matches the first part for assets and completely ignores the matching for groups and thus returns other groups that are not even connected to devices. I am not sure why this is the cause.
Why don't you returned directly each type like this: Group, Asset, Device?*
The OPTIONAL MATCH will return all nodes even if they didn't match all relationships
Because i'm only interested for searching those assets and groups that have a device attached to it, the rest are super useless. Is there a way to delete the null row, I feel like that it would be faster this way?
CALL db.index.fulltext.queryNodes('livesearch', '*t*')
YIELD node
MATCH (g:Group)-[:GROUPS]->(node)<-[:ON]-(:Deploy)<-[:SCHEDULED]-(d:Device)
RETURN DISTINCT collect(d{.sigfox_id, node, g}) AS assetdata, node
UNION ALL
CALL db.index.fulltext.queryNodes('livesearch', '*t*')
YIELD node
MATCH (node)-[:GROUPS]->(a:Asset)<-[:ON]-(:Deployment)<-[:SCHEDULED]-(d:Device)
RETURN DISTINCT collect(d{.sigfox_id, a, node}) AS assetdata, node
This request has two parts:
the first will return all Asset nodes
the second will return all Group nodes
You need to use MATCH clause to make sure there is a path between Asset and Device for the first part and Group and Device for the second part