Search code examples
neo4jlucenecypherfull-text-search

Neo4j Lucene fulltext search


I create an fulltext index:

CREATE FULLTEXT INDEX skillAndTranslationsNamesAndDescriptions FOR (n:Skill|Translation) ON EACH [n.name, n.description]

Also, added a node with name = bash-variables

I'm able to successfully query this node with the following query:

match (s:Skill {name: 'bash-variables'}) return s;

Now, I'd like to query this node by Neo4j Cypher fulltext search:

CALL db.index.fulltext.queryNodes("skillAndTranslationsNamesAndDescriptions", "bash-var*") YIELD node, score
OPTIONAL MATCH (node)-[:ALIAS_FOR*]->(skillForAlias:Skill)
OPTIONAL MATCH (node)<-[:CONTAINS]-(skillForTrans:Skill)
RETURN node.name, node.id, skillForAlias.name, skillForAlias.id, skillForTrans.name, skillForTrans.id, score, labels(node)
LIMIT 100

and it returns nothing.

I think the reason is in the Lucene special character - but I don't knowhow to properly handle this. Simply escaping this with \- didn't help.

What am I doing wrong and how to fix it?


Solution

  • Try using the "whitespace" analyzer:

    CREATE FULLTEXT INDEX skillAndTranslationsNamesAndDescriptions 
    FOR (n:Skill|Translation) ON EACH [n.name, n.description] 
    OPTIONS { indexConfig: {`fulltext.analyzer`: 'whitespace'}}