Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Using Neo4j Fulltext Index with Gremlin
// Example using the Neo4j Fulltext Index with Gremlin-Groovy
// by James Thornton, http://jamesthornton.com
import com.tinkerpop.blueprints.pgm.impls.neo4j.util.Neo4jVertexSequence;
import com.tinkerpop.blueprints.pgm.impls.neo4j.util.Neo4jEdgeSequence;
Graph g = new Neo4jGraph('/tmp/neo4jmovies');
indexManager = g.getRawGraph().index();
indexConfig = ["provider":"lucene", "type":"fulltext"]
fulltextMovies = indexManager.forNodes( "movies-fulltext", indexConfig);
// Add some nodes and add them to the fulltext index
g.setMaxBufferSize(0);
g.startTransaction();
matrix = g.addVertex(['name':'The Matrix']);
reloaded = g.addVertex(['name':'The Matrix Reloaded']);
neo = g.addVertex(['name':'Neo']);
g.addEdge(matrix,neo,'character');
g.addEdge(reloaded,neo,'character');
fulltextMovies.add( matrix.getRawElement(), "title", "The Matrix" );
fulltextMovies.add( reloaded.getRawElement(), "title", "The Matrix Reloaded" );
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
// Return matched movie names
hits = fulltextMovies.query( "title", "matrix" )
vertices = new Neo4jVertexSequence(hits,g);
println vertices._().name.toList();
// Return movie character names
hits = fulltextMovies.query( "title", "matrix" )
vertices = new Neo4jVertexSequence(hits,g);
println vertices._().out('character').name.toList();
g.shutdown();
@espeed
Owner

To run this, do:

$ ./gremlin.sh -e neo4j-fulltext-gremlin.groovy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.