Created
January 4, 2012 04:41
-
-
Save espeed/1558540 to your computer and use it in GitHub Desktop.
Using Neo4j Fulltext Index with Gremlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this, do: