Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-03-2020 12:07 AM
Hi neo4j community,
I don't quite understand why my query doesn't return NULL when no records are found. It just returns (no changes, no records) when i search for something that is not there.
CALL db.index.fulltext.queryNodes('test', 'car_type:test1')
YIELD node
with coalesce(collect(node.car_type)) as test, node
CALL apoc.do.when(
size(test) = 0,
'RETURN NULL',
'MATCH (c:Car:Vehicle)-[:RACE]->(:Formula1)
WHERE c.car_type = node.car_type
RETURN DISTINCT c',
{test:test,node:node}) YIELD value
RETURN value
Thanks in advance
Solved! Go to Solution.
07-03-2020 12:46 AM
That's why I think, the next part of your request is not working, you can't get the size of something that doesn't exist
To be able to work, it should return at least an empty collection []
and the node
07-03-2020 12:30 AM
Hello @tarendran.vivekanand
Can you check what is returned by:
CALL db.index.fulltext.queryNodes('test', 'car_type:test1')
YIELD node
RETURN coalesce(collect(node.car_type)) AS test, node
Regards,
Cobra
07-03-2020 12:46 AM
That's why I think, the next part of your request is not working, you can't get the size of something that doesn't exist
To be able to work, it should return at least an empty collection []
and the node
07-03-2020 01:07 AM
Is there a work around this?
07-03-2020 01:10 AM
You don't need to specify the property since you defined the index on it. So try:
CALL db.index.fulltext.queryNodes('test', 'test1')
YIELD node
RETURN coalesce(collect(node.car_type)) AS test, node
07-03-2020 01:14 AM
I am doing that cause I have index other properties. Thus, when I search I want to specify the property I want to search.
07-03-2020 01:19 AM
Oh I see, so there is a syntax mistake
It should be: CALL db.index.fulltext.queryNodes('test', 'car_type:"test1"')
07-03-2020 01:24 AM
If I do that then I won't be able to do any fuzzy search
07-03-2020 01:25 AM
Why? You can use a parameter: CALL db.index.fulltext.queryNodes('test', 'car_type:$arg')
07-03-2020 01:31 AM
Same thing, it only works if I DON'T do a fuzzy search
07-03-2020 01:32 AM
Can you give me several examples about what you want to search?
07-03-2020 01:41 AM
Nodes Created:
CREATE (c:Car:Vehicle {car_type:'Sedan', car_model:'Toyota', car_description:'Used in last 5 years'})
CREATE (c:Car:Vehicle {car_type:'Sedan', car_model:'Toyota', car_description:'Unused in last 3 months'})
CREATE (c:Car:Vehicle {car_type:'Sedan', car_model:'Honda', car_description:'Used in last 2 years'})
MERGE (c)-[:Drives]->(:Driver)
In this example when I search for car_model: *toy* AND car_description:*use*
I want the (1st & 2nd) results returned and its attached nodes and if I search for something that isnt there I want to return NULL.
07-03-2020 01:44 AM
I don't understand why the last request I sent you could not work???
07-03-2020 01:55 AM
This is how i added the parameter :param filter: 'car_type:*test*'
CALL db.index.fulltext.queryNodes('test', $filter)
YIELD node
WITH coalesce(collect(node.car_type)) AS test, node
CALL apoc.do.when(
size(test) = 0,
'RETURN NULL',
'MATCH (c:Car:Vehicle)-[:RACE]->(:Formula1)
WHERE c.car_type = node.car_type
RETURN DISTINCT c',
{test:test,node:node}) YIELD value
RETURN value
When i do this I get no changes no records when i search for something that doesnt exists
07-03-2020 02:01 AM
Use: :param arg: 'car_type:"*test*"'
07-03-2020 02:05 AM
I get no changes, no results
07-03-2020 02:05 AM
And: :param arg: 'car_type:"*Sedan*"'
07-03-2020 02:10 AM
Same thing no changes, no results. Also its my bad the query below still gets no changes no records when I search for something that isnt there
CALL db.index.fulltext.queryNodes('test', $filter)
YIELD node
RETURN coalesce(collect(node.car_type)) AS test, node
07-03-2020 02:12 AM
Can you try:
CALL db.index.fulltext.queryNodes('test', 'car_type:"*Sedan*"')
YIELD node
RETURN coalesce(collect(node.car_type)) AS test, node
07-03-2020 02:15 AM
No changes no records. I believe the double quotes make it an exact match
07-03-2020 02:17 AM
Ah, so, did you try to test without?
07-03-2020 02:22 AM
yes it works when I search for something that exists but won't work when I search for something that doesn't exists
07-03-2020 02:25 AM
It makes sense no?
Try:
RETURN coalesce(collect(node.car_type), []) AS test, node
07-03-2020 02:32 AM
No still doesn't work. I get why it doesn't work. I was hoping to get more than just empty square brackets in the response so that I know the reason is that there was actually no results from what I am searching.
I guess there is really no work around this.
07-03-2020 02:35 AM
If the thing you are searching doesn't not exist, the YIELD node will return nothing, that's why you must ass something at the end of your list in coalesce
to make sure to return something
All the sessions of the conference are now available online