Neo4j cypher query Double(NaN) issue

83 views Asked by At

I have a query like I wrote below. I couldn't solve the error I gave below even after a lot of effort. I encounter this error when I do any sorting operation. But not always, in specific cases. I think sometimes my query doesn't return Double(NaN) values most of the time, so I rarely encounter this error.

MATCH (news:News {newsId: "/infografik/jurnalist/turkiye-sma-hastaligi-icin-yeni-adimlar-atiyor-26685"})
WITH news
WHERE news.cleanTitle IS NOT NULL

MATCH (otherNews:News {category: news.category})
WHERE news <> otherNews AND otherNews.cleanTitle IS NOT NULL

WITH otherNews,
     apoc.text.sorensenDiceSimilarity(news.cleanTitle, otherNews.cleanTitle) AS sorensen
ORDER BY sorensen DESC
LIMIT 10
RETURN otherNews.title, sorensen, otherNews.category;

Error:

Neo.ClientError.Statement.TypeError Wrong argument type: Can't coerce Double(NaN) to String

I want to see results sorted correctly. When I don't sort, I can see the results without any problems. But I need the sorted version. I tried converting the Sorensen value to string, eliminating Null or NaN values. But I was not successful.

1

There are 1 answers

0
TylerH On

Migrating OP's solution to an answer:

I saw that the error was resolved when I placed the "LIMIT 10" line above the "RETURN" line. But this time the results were very inconsistent. If I don't set any limits, I still encounter the same error. I can increase my limit amount up to a certain number >depending on the data I use. As I get closer to the limit I can reach, the accuracy of >my returned data increases. How can I overcome this problem?

Fix: change to this piece of code solved my problem. Thanks to Finbar Good's comment.

apoc.text.sorensenDiceSimilarity(toString(news.cleanTitle), toString(otherNews.cleanTitle))