Skip to content

Commit

Permalink
Simplify the LuceneFulltextUpdater… and …AnalyzerTests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Sep 20, 2017
1 parent d4ca73e commit cef28c7
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 166 deletions.
Expand Up @@ -23,7 +23,6 @@
import org.apache.lucene.analysis.sv.SwedishAnalyzer; import org.apache.lucene.analysis.sv.SwedishAnalyzer;
import org.junit.Test; import org.junit.Test;


import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;


import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
Expand All @@ -40,16 +39,11 @@ public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception
fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ), provider ); fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ), provider );
provider.init(); provider.init();


long firstID; long id;
long secondID;
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Node node = db.createNode(); createNodeIndexableByPropertyValue( "Hello and hello again, in the end." );
Node node2 = db.createNode(); id = createNodeIndexableByPropertyValue( "En apa och en tomte bodde i ett hus." );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", "Hello and hello again, in the end." );
node2.setProperty( "prop", "En apa och en tomte bodde i ett hus." );


tx.success(); tx.success();
} }
Expand All @@ -59,9 +53,9 @@ public void shouldBeAbleToSpecifyEnglishAnalyzer() throws Exception
assertExactQueryFindsNothing( reader, "and" ); assertExactQueryFindsNothing( reader, "and" );
assertExactQueryFindsNothing( reader, "in" ); assertExactQueryFindsNothing( reader, "in" );
assertExactQueryFindsNothing( reader, "the" ); assertExactQueryFindsNothing( reader, "the" );
assertExactQueryFindsIds( reader, "en", secondID ); assertExactQueryFindsIds( reader, "en", id );
assertExactQueryFindsIds( reader, "och", secondID ); assertExactQueryFindsIds( reader, "och", id );
assertExactQueryFindsIds( reader, "ett", secondID ); assertExactQueryFindsIds( reader, "ett", id );
} }
} }
} }
Expand All @@ -75,25 +69,20 @@ public void shouldBeAbleToSpecifySwedishAnalyzer() throws Exception
fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ), provider ); fulltextFactory.createFulltextIndex( "bloomNodes", NODES, singletonList( "prop" ), provider );
provider.init(); provider.init();


long firstID; long id;
long secondID;
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Node node = db.createNode(); id = createNodeIndexableByPropertyValue( "Hello and hello again, in the end." );
Node node2 = db.createNode(); createNodeIndexableByPropertyValue( "En apa och en tomte bodde i ett hus." );
firstID = node.getId();
secondID = node2.getId();
node.setProperty( "prop", "Hello and hello again, in the end." );
node2.setProperty( "prop", "En apa och en tomte bodde i ett hus." );


tx.success(); tx.success();
} }


try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) ) try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) )
{ {
assertExactQueryFindsIds( reader, "and", firstID ); assertExactQueryFindsIds( reader, "and", id );
assertExactQueryFindsIds( reader, "in", firstID ); assertExactQueryFindsIds( reader, "in", id );
assertExactQueryFindsIds( reader, "the", firstID ); assertExactQueryFindsIds( reader, "the", id );
assertExactQueryFindsNothing( reader, "en" ); assertExactQueryFindsNothing( reader, "en" );
assertExactQueryFindsNothing( reader, "och" ); assertExactQueryFindsNothing( reader, "och" );
assertExactQueryFindsNothing( reader, "ett" ); assertExactQueryFindsNothing( reader, "ett" );
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.collection.primitive.PrimitiveLongSet; import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
Expand Down Expand Up @@ -75,6 +76,33 @@ protected FulltextProvider createProvider()
return new FulltextProvider( db, LOG, availabilityGuard, scheduler ); return new FulltextProvider( db, LOG, availabilityGuard, scheduler );
} }


protected long createNodeIndexableByPropertyValue( Object propertyValue )
{
return createNodeWithProperty( "prop", propertyValue );
}

protected long createNodeWithProperty( String propertyKey, Object propertyValue )
{
Node node = db.createNode();
node.setProperty( propertyKey, propertyValue );
return node.getId();
}

protected long createRelationshipIndexableByPropertyValue( long firstNodeId, long secondNodeId, Object propertyValue )
{
return createRelationshipWithProperty( firstNodeId, secondNodeId, "prop", propertyValue );
}

protected long createRelationshipWithProperty( long firstNodeId, long secondNodeId, String propertyKey,
Object propertyValue )
{
Node first = db.getNodeById( firstNodeId );
Node second = db.getNodeById( secondNodeId );
Relationship relationship = first.createRelationshipTo( second, RELTYPE );
relationship.setProperty( propertyKey, propertyValue );
return relationship.getId();
}

protected void assertExactQueryFindsNothing( ReadOnlyFulltext reader, String query ) protected void assertExactQueryFindsNothing( ReadOnlyFulltext reader, String query )
{ {
assertExactQueryFindsIds( reader, query ); assertExactQueryFindsIds( reader, query );
Expand Down Expand Up @@ -108,11 +136,16 @@ protected void assertQueryResultsMatch( PrimitiveLongIterator result, long[] ids
} }


protected void setNodeProp( long nodeId, String value ) protected void setNodeProp( long nodeId, String value )
{
setNodeProp( nodeId, "prop", value );
}

protected void setNodeProp( long nodeId, String propertyKey, String value )
{ {
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
Node node = db.getNodeById( nodeId ); Node node = db.getNodeById( nodeId );
node.setProperty( "prop", value ); node.setProperty( propertyKey, value );
tx.success(); tx.success();
} }
} }
Expand Down

0 comments on commit cef28c7

Please sign in to comment.