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.junit.Test;

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

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

long firstID;
long secondID;
long id;
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
Node node2 = db.createNode();
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." );
createNodeIndexableByPropertyValue( "Hello and hello again, in the end." );
id = createNodeIndexableByPropertyValue( "En apa och en tomte bodde i ett hus." );

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

long firstID;
long secondID;
long id;
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode();
Node node2 = db.createNode();
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." );
id = createNodeIndexableByPropertyValue( "Hello and hello again, in the end." );
createNodeIndexableByPropertyValue( "En apa och en tomte bodde i ett hus." );

tx.success();
}

try ( ReadOnlyFulltext reader = provider.getReader( "bloomNodes", NODES ) )
{
assertExactQueryFindsIds( reader, "and", firstID );
assertExactQueryFindsIds( reader, "in", firstID );
assertExactQueryFindsIds( reader, "the", firstID );
assertExactQueryFindsIds( reader, "and", id );
assertExactQueryFindsIds( reader, "in", id );
assertExactQueryFindsIds( reader, "the", id );
assertExactQueryFindsNothing( reader, "en" );
assertExactQueryFindsNothing( reader, "och" );
assertExactQueryFindsNothing( reader, "ett" );
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.io.fs.FileSystemAbstraction;
Expand Down Expand Up @@ -75,6 +76,33 @@ protected FulltextProvider createProvider()
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 )
{
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 )
{
setNodeProp( nodeId, "prop", value );
}

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

0 comments on commit cef28c7

Please sign in to comment.