Search code examples
searchneo4jfull-text-indexingneography

Neo4j, Neography: Making search smarter


I had been using full-text-indexes to search through the neo4j graph database. But in case the user enters a wrong spelling or the query doesn't match any result. Is there a way to handle this or a did you mean kind of feature in such cases?

Also how can the search be made smarter based on the what queries a user is searching? I came across SearchKick but this doesn't have any integration with neography.


Solution

  • You can introduce fuzziness into your lucene query. You can do it by appending a '~' sign to your query and specify the factor, e.g. name:mistqke~0.8 should still find the text "mistake". The fuzziness factor is between 0 and 1. A value closer to 1 will match with a higher similarity.

    If you want to combine a wildcard and a fuzzy query, you'll could use something like this:

    START n=node:index('name:mistqke~0.8 or name:*mistqke*')
    RETURN DISTINCT n;
    

    Mind the 'OR' in the lucene query and 'DISTINCT' in the RETURN clause.