Using Neo4j fulltext indexing for Contains queries

(pmneo4j) #1

I'm using neo4j 3.5, and have about 9 million user nodes. I was trying to implement the following query, but it was taking way too long:

MATCH (users:User) WHERE (users.username CONTAINS "joe" OR users.first_name CONTAINS "joe" OR users.last_name CONTAINS "joe")
RETURN users

I was hoping to take advantage of neo4j 3.5's newest fulltext indexing feature by creating the following index:

CALL db.index.fulltext.createNodeIndex('users', ['User'], ['username', 'first_name', 'last_name'])

and then querying the db like so

CALL db.index.fulltext.queryNodes('users', joe)
YIELD node
RETURN node.user_id

I thought this would work the same as contains and return users whose username, first_name or last_name contains joe (eg: myjoe12, joe12, 12joo, 44joeseph, etc.) but it seems to be returning users whose fields are joe exactly or contain joe separated by a whitespace (eg: Joe B, Joe y1), I tried using joe* in the query but that only returns everything starting with joe, I want to return everything containing joe or whatever search term. What would be the best way to go about this?

(Michael Black) #2

I think this article has a good explanation how to search