Anurag Sharma
Anurag Sharma

Reputation: 5049

Running 2 cypher queries for full text search returns error in neo4j

I have a task in hand where for an input job title pairs I have to output how similar these 2 titles are. For similarity I will be taking into account different factors like common relationships between 2 job title nodes etc.

I am currently into the 1st part, i.e getting a best matching job title node for input job title. I am using the full-text-search capability of neo4j to solve this. I have come up with the following query

CALL db.index.fulltext.queryNodes("full-text-job-title", '"software engineer" OR (software~0.7 engineer~0.7)') yield node, score
with collect(node)[..1] as matchedTitles1
CALL db.index.fulltext.queryNodes("full-text-job-title", '"software developer" OR (software~0.7 developer~0.7)') yield node, score
with collect(node)[..1] as matchedTitles2
return matchedTitles1[0], matchedTitles2[0]

It returns the following error

Neo.ClientError.Statement.SyntaxError
Neo.ClientError.Statement.SyntaxError: Variable `matchedTitles1` not defined (line 5, column 8 (offset: 351))
"return matchedTitles1[0], matchedTitles2[0]"
        ^

I am unable to solve this error. Also I want to return the top matching job-title node for each of the input job title pair. Currently I have come up with this - with collect(node)[..1] as matchedTitles1, but I think there has to be a better way to return the top matching job-title node

Any help will be deeply appreciated.

Upvotes: 0

Views: 204

Answers (1)

Pablissimo
Pablissimo

Reputation: 2905

Your syntax error is because you're not passing through matchedTitles1 in your second WITH statement. Everything from before the WITH that you want to refer to after the WITH needs to be included in the WITH statement.

The following is valid Cypher:

CALL db.index.fulltext.queryNodes("full-text-job-title", '"software engineer" OR (software~0.7 engineer~0.7)') yield node, score
with collect(node)[..1] as matchedTitles1
CALL db.index.fulltext.queryNodes("full-text-job-title", '"software developer" OR (software~0.7 developer~0.7)') yield node, score
with collect(node)[..1] as matchedTitles2, matchedTitles1 // Pass through matchedTitles1 from the first CALL so it's visible in the RETURN
return matchedTitles1[0], matchedTitles2[0]

Upvotes: 2

Related Questions